ASP.Net Inproc session restarted after markup change in VS2012

前端 未结 5 1962
说谎
说谎 2020-12-15 06:56

I upgraded my development machine to Windows 8 and Visual Studio 2012.

I\'m testing my ASP.Net applications (also upgraded to .net 4.5) on a local IIS.

One t

相关标签:
5条回答
  • 2020-12-15 07:43

    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 post http://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.

    0 讨论(0)
  • 2020-12-15 07:47

    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,

    0 讨论(0)
  • 2020-12-15 07:49

    you can try SQL server session state mode .

    0 讨论(0)
  • 2020-12-15 07:51

    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..

    0 讨论(0)
  • 2020-12-15 07:53

    One maybe related issue: IIS (as well as ASP.NET Development Server) restarts the application after you check-out a file from TFS.

    I have found the solution here: http://forums.iis.net/p/1200785/2055480.aspx/1?IIS+Express+restarts+site+when+a+file+is+checked+out

    1. Navigate to: %USERPROFILE%\AppData\Roaming\Microsoft\VisualStudio\11.0
    2. Delete the app_offline.htm file.
    3. Create a folder named app_offline.htm
    0 讨论(0)
提交回复
热议问题