问题
I have a webserver, and my team have set the application pool for the web application to 3 for resilence and performance. However, we have stumbled upon a problem where part of the application is not fully working.
We believe the problem lies where this part of the application uses sessions, and we think that when the data is posted back it doesn't link back to the correct worker process.
However, I am not sure about this, or whether I should be using SessionState in the web.config. If I am right, should the mode be InProc, SessionState, or whatever? Should there be a timeout on the session?
Can someone please advise me?
回答1:
You cannot use InProc in a multithreaded way (3 threads in the app pool) without guaranteeing that each request goes to the same thread.
InProc literally means in process, as in the memory of the current thread.
If you move to another storage method, say, to the database, then session can be shared across all instances of a given application.
I suggest reading this
回答2:
So you have broken your application into three parts on the same server, each running under its own application pool in IIS? I would challenge the assumptions behind doing this but that is really not your question.
I do not think you can do this and share session state using the out-of-the-box tools. It uses the site (metabase) path as part of the session state "key", so sessions from different sites do not collide.
But if you could do it, you would need to use one of the out-of-proc sessionState modes (StateServer or SQLServer).
I haven't tried the following, but they may help you.
Here is a link to a Code Project article that describes modifying SQL Server Sessioning to group sites and share sessions.
Here is a link to an ASP 101 article that describes one way to share sessions with child sites. Not sure if this would work in your case with different application pools.
EDIT:
Ah, a web garden. Yes, your worker processes don't share InProc session data. You need to use an external provider. The StateServer works fine. You'll need to enable the ASP.NET State Service on a server and update your web.config to use it. There are some things to consider with it:
- Is it running on a different server than IIS? Need to enable remote connections.
- Do you have multiple web servers? Need to define a machine key.
- Are you storing objects in session? Need to mark them serializable.
There are many resources online to help with this, here is an example blog post.
来源:https://stackoverflow.com/questions/5009563/session-state-and-application-pool