ASP.Net Inproc session restarted after markup change in VS2012 ASP.Net Inproc session restarted after markup change in VS2012 asp.net asp.net

ASP.Net Inproc session restarted after markup change in VS2012


I'm not going to try to take the credit for this but the answer is buried in the 11th comment on the original question by @Anand:

Add this key in web.config:

<appSettings><add key="PageInspector:ServerCodeMappingSupport" value="Disabled" /></appSettings>

and the problem goes away. VS becomes far more responsive too. Only downside is you lose the server-side trickery from Page Inspector.

Hopefully MS will provide a fix soon..


The problem here is your application is doing a dynamic compile which means any changes to the markup files will cause the application to restart. Any application restart, as you know, will dump the InProc session.

A "Web Application" on your local template is set differently so it isn't restarting the whole application. There are advantages to having precompilation though.

There's a couple of ways around this.

Why this is happening

ASP.NET 4.5 allows you to run "web pages" side by side with "web applications" by default. This is likely what's causing changes to an aspx to fire a precomilation (which "web pages" have to do every time there is a change).More info here:http://msdn.microsoft.com/en-us/library/dd547590.aspx

There is also quite a few changes to optimise the web server in the new version. You can see details of those changes here and they also can explain the change when you upgrade.http://www.asp.net/vnext/overview/aspnet/whats-new

The solution is still the same regardless and updating single aspx files on the fly is not recommended. If it's unavoidable, then restart will have happened eventually on any setup so it's worth using one of the below solutions anyway.

Solutions

Compilation Mode

Check the CompilationMode in your web.config. For more info check out this posthttp://www.campusmvp.net/compilationmode-avoiding-aspx-page-compilation-to-improve-scalability-in-sites-with-thousands-of-pages/

This can be set on a server level too so you can get differences by environment.

Session State Mode

You can run your session state in StateServer mode or using Sql server. The ASP.NET state server will be sitting on your server if .net is installed and just needs to be set to auto start. You can then just switch it in the config.

<sessionState mode="StateServer" useHostingIdentity="true" cookieless="false" timeout="120" stateConnectionString="tcpip=127.0.0.1:42424" />

We always run using the ASP.NET state server for development and in many cases in production.I find when testing long user pathways (like a form wizard with many forms) it's very annoying to have session blatted every time you rebuild. That will also mean you don't lose session on app restarts.

You can also use SQL server in the same way.

NOTE: You must remember that if you are serialising classes into session state and you make changes, you will need to manually restart the state server or you'll get serialization errors. This is very rare, but just to be aware of in production environments.


when using in-proc mode, your session data is hosted at server memory. You should verify on your IIS about application pool recycle time.

Cheers,