Preserve ASP.NET InProc session while W3WP (IIS) process recycling

I understand that all InProc session data always disappears when the w3wp owner process gets recycled as it only resides in w3wp memory.

I was wondering if it is possible, if it is possible to cache the session data when the rework is happening somewhere outside of the process, and then reinitializes (and rebuilds) the session when it comes back. This way I would get the speed of InProc with the reliability of an external server like a server when needed. Is it possible?

+2


source to share


3 answers


No, It is Immpossible. There is no API to "warm up" in a session, session or cache. In any case, such a solution would be unreliable. You could not guarantee that the last thing your application did was export the current session state, so you can never expect the imported data to be current.

You can use an out-of-process state server on the same host as your web application. The web application is then free to recycle while retaining the state information. This is slightly faster than using SQL Server for session management, since you don't have to deal with the SQL or network overhead on another machine, the only way that is worse than the session process is that the data has to marshal across the process boundaries. but as long as you don't have a lot of rapidly changing session data, it shouldn't be noticeable at all.



There are other alternatives, such as Microsoft's project code called "Velocity" or ScaleOut Software SessionServer (among others, I'm sure) that offer distributed caching mechanisms that can keep session or cache state in sync between servers in a server farm without resorting to using SQL Server.

Unlike another user, I would not use ViewState to store session data, if at all possible. Firstly, this is not the true state of the session, if the user navigates backwards or forwards, they may be lost. Secondly, it's pretty insecure. Third, it causes massive page bloat if misused.

+2


source


Perhaps you can store enough information in the cookie (or ViewState) so that you can re-create a session based on that data in the event that the workflow has been refactored.



Or you can create your own state server (like a Windows service) where you store a portion of your session and access that service from a web application via remote access or the like.

0


source


You should use SQL Server for session state if that's your intention. What you want are sessions that can recover after the host processes have finished completely. Neither inproc nor Stateserver maintains that as soon as they go down they lose all data. You could write your own state method, but that would be time consuming. Here's how to do it:

http://www.exforsys.com/tutorials/asp.net-2.0/asp.net-2.0-customizing-the-session-state-mechanism.html

What you can do is not use sessions at all, but rather rely on ViewState. If you have a high traffic site that allows you to redirect your workload to customers.

0


source







All Articles