Tips and Tricks in a world of Mix

Posts tagged ‘publish’

Setting constant parameter in WebAPI

So the mission was to set static member for connectionString , so that we’ll get the string from web.config just once. On the way we did Encrypt and Decrypt of the connectionString.

So the trouble was that we couldn’t be sure that the static field is staying or going on the request- response model of WebApi.

The easy solution was to reuse the existing code to init HttpContext.Current.Application[“connectionString”] value if it’s null at the global.asax at Application_Start function.

When initialized in that function at the host/server side of the distributed system , the HttpContext.Current.Application[“connectionString”] is initialized for the first time and until the IISReset.

If you want something constant for one request the way to go is to put it in Init function at gobal.asax 

The trouble was that the Application variable has been resetting itself each request.

The solution was that because of decryption that has been saving the web.config it has been resetting the site values held by the IIS, so actually it has been recycling the site data resetting the Application variables values also.

At the end the encryption has been executed on publish to the server, the decrypt has been decrypting the secured section but hasn’t been saving it back , so the web.config actually haven’t changed throughout running host , so the Application data kept intact.

Mvc with Windows Authentication results – /login.aspx?ReturnUrl=%2f – solution

When first published on server the MVC  has been Anonymous. then changed to windows Authentication caused

The resource cannot be found.

The url has been the standart need one but – /login.aspx?ReturnUrl=%2fEgged.Tnua.TimeTable%2fHome

The solution is :

adding the following lines to the AppSettings section of my web.config file in appSettings:

<add key="autoFormsAuthentication" value="false" />
<add key="enableSimpleMembership" value="false"/>

Weirdly enough – solved the problem!

Found it here

Minify JS on rebuilding the web


Download JSMIN from

Instead of opening the WebSite  project , open a WebApp .

(you can see diff here and here – actually it’s an issue by itself )

So , on the Property Pages of your WebApp –> goto  build events –>

build one time script for rebuilding the minified files on each build/rebuild of the project like so :

"$(ProjectDir)..\jsmin\jsmin" < "$(ProjectDir)\scripts\models\employee.js” > "$(ProjectDir)\scripts\models\employee.min.js"

(you must adjust the script line accordingly to the position of the JSMIN in your project)

this will create a few lines of code ..

then you add instead of the regular employee.js  the newly created employee.min.js to your index.html (start page with references to JavaScript files )

Also , be careful to add newly created files to the project – Include in project . Check that it also entered into the Source Safe you are using.

Check in to all and let your team use the minified files on rebuilding the project.

Tag Cloud

%d bloggers like this: