3
votes

I have an application that has been having issues with losing session, and I'm almost positive it has to do with the application pool recycling too often.

I wanted to try an out of process solution and have configured SQLServer sessionState, but when I recycle the worker process my session is still being blown away. Here is my web.config

<sessionState cookieless="false" stateConnectionString="tcpip=localhost:42424"  mode="SQLServer" sqlConnectionString="Data Source=(local;User ID=user;Password=password" timeout="180" />

I've ran the appropriate sql scripts to setup the database and I can see that a session is created and stored in the database, but if i change the web.config or manually recycle the worker process my session is lost. What am I doing wrong??

Side note, I'm receiving the exact same behavior with StateServer mode. I seemingly configure it properly, I can see the State service memory footprint get bigger when I login ....I tried to push a non serialized object into and received an error....but when I recycle the app pool or change the web.config I lose session....

I've also tried to set up the Memcached session provider (which is what I would really like to use) that can be found here: http://memcachedproviders.codeplex.com/releases/view/10468

and it is also doing the same thing! I can see the session being created in the database, and I will get an error pertaining to serialization when I try to interact with a non-serialized object....but I lose the session when the app pool is recycled.
After enabling some logging I'm seeing this in the event viewer: Event code: 1003 Event message: Application compilation is starting

Nobody?? I really need to get out of process session state working....help!!

1
Maybe you reset on your global.asax something that affect your session data ? - Aristos
Is everything you're putting the session serializable? - Jon Adams
How are you establishing that the session is lost? How are you using session state? Do you have the same issues if you use State Server rather than SQL Server? - Damien_The_Unbeliever
@Aristos: No, I have nothing in the global.asax after Application_Start, which contains my URL routes. - Cognitronic
@JohAdams: Yes, I believe I have everything that's being loaded marked as Serializable...but even if I didn't wouldn't it just throw an exception instead of kill my session? Session seems to be working just fine and I see the record inserted into the ASPState database...I just lose my session when the App Pool is recycled. - Cognitronic

1 Answers

0
votes

Check your settings for Machine Key (assuming IIS 7.5). If your web server is set to autogenerate the machine key, it is possible that it is generating a new key when your application recycles and that is causing you to lose session.

See this link here for an easy way generate unique machine keys for your web application. You should be able to generate them at either the web server or web application level.

http://blogs.msdn.com/b/amb/archive/2012/07/31/easiest-way-to-generate-machinekey.aspx

Also, FWIW, the SQL Server Session State manager is very talky with the database. It works, but you will be hitting the database for every request using that Session provider.