会话状态和应用程序池
我有一个 Web 服务器,我的团队已将 Web 应用程序的应用程序池设置为 3,以提高弹性和性能。然而,我们偶然发现了一个问题,即应用程序的一部分无法完全运行。
我们认为问题在于应用程序的这一部分使用会话,并且我们认为当数据回发时,它不会链接回正确的工作进程。
但是,我不确定这一点,或者我是否应该在 web.config 中使用 SessionState。如果我是对的,模式应该是 InProc、SessionState 还是其他?会话应该有超时吗?
有人可以告诉我吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法以多线程方式(应用程序池中的 3 个线程)使用 InProc,而不保证每个请求都转到同一线程。
InProc字面意思是进程中,即在当前线程的内存中。
如果您转移到另一种存储方法,例如数据库,则可以在给定应用程序的所有实例之间共享会话。
我建议阅读此
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
那么您是否已将应用程序分成同一服务器上的三个部分,每个部分都在 IIS 中自己的应用程序池下运行?我会质疑这样做背后的假设,但这确实不是你的问题。
我认为您无法使用开箱即用的工具来执行此操作并共享会话状态。它使用站点(元数据库)路径作为会话状态“密钥”的一部分,因此来自不同站点的会话不会发生冲突。
但如果您能做到这一点,您将需要使用进程外 sessionState 模式之一(StateServer 或 SQLServer)。
我没有尝试过以下方法,但它们可能会对您有所帮助。
以下是代码项目文章的链接,该文章描述了将 SQL Server 会话修改为组网站和分享会。
以下是 ASP 101 文章 的链接,该文章描述了一种共享方式与子站点的会话。不确定这是否适用于您使用不同应用程序池的情况。
编辑:
啊,一个网络花园。是的,您的工作进程不共享 InProc 会话数据。您需要使用外部提供商。 StateServer 工作正常。您需要在服务器上启用 ASP.NET 状态服务并更新 web.config 才能使用它。有一些事情需要考虑:
比IIS?需要开启远程功能
连接。
服务器?需要定义一台机器
钥匙。
会议?需要标记它们
可序列化。
网上有很多资源可以帮助解决此问题,这里有一个示例 博客文章。
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:
than IIS? Need to enable remote
connections.
servers? Need to define a machine
key.
session? Need to mark them
serializable.
There are many resources online to help with this, here is an example blog post.