ASP.NET 处于 Proc 会话状态
我们有一个使用 FormsAuthentication 的 MVC Web 应用程序,并且还在会话变量中存储了几个变量。我们最近遇到了一些情况,会话变量丢失,但用户仍然登录。快速谷歌让我找到了几篇SO文章,其中提到In Proc Session State经常丢失,并且如果我们需要它持续存在,我们应该考虑转向非 In Proc 解决方案。
来自经典的 ASP 背景,我们在会话的生命周期中依赖会话状态,现在我根本不能依赖它,这似乎有点令人困惑。如果 In Proc Session State 可能突然丢失,那么它对任何人来说肯定没有任何价值吗?我错过了什么吗?
我意识到将其存储在 SQL 服务器中有它的好处,但对于流量很少的小型 Web 应用程序来说,In Proc 是一个理想的解决方案,值得信赖。
We have an MVC web app that uses FormsAuthentication and also stores a couple of variables in Session variables. We've encountered a few situations lately where the session variables are lost, but the user is still logged in. A quick Google lead me to a few SO articles mentioning that In Proc Session State is regularly lost and that if we require it to persist, we should consider moving to a non In Proc solution.
Coming from a classic ASP background, where we relied on Session state for the lifetime of the session, it seems a bit baffling that I now can't rely on it at all. Surely In Proc Session State is of no value to anyone if it can be lost at the drop of a hat? Am I missing something?
I realise that storing it in an SQL server has it's benefits, but for small webapps with little traffic, In Proc is an ideal solution, could it be relied upon.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ASP.NET 会话状态能够在与 ASP.NET 主机进程不同的进程中运行。如果会话状态位于单独的进程中,则 ASP.NET 进程可以来来去去,而会话状态进程仍然可用。当然,您仍然可以像经典 ASP 一样在进程中使用会话状态。
您不必使用 SQL Server 在进程外存储会话数据,您可以使用进程外状态服务器,它可以与 Web 服务器位于同一服务器的内存中。
您可以在 http://msdn.microsoft.com/en-us/library/ms972429.aspx
ASP.NET session state is able to run in a separate process from the ASP.NET host process. If session state is in a separate process, the ASP.NET process can come and go while the session state process remains available. Of course, you can still use session state in process similar to classic ASP, too.
You don’t have to use SQL server to store session data in out of process, you can use out of process state server which can be in memory on the same server as the web server.
You can read more about how to configure out of process session state under http://msdn.microsoft.com/en-us/library/ms972429.aspx
据我所知,重新编译应用程序和回收应用程序池后,进程内会话状态会丢失。如果内存不足或有定期重启时间间隔,应用程序池可能会被回收。
As far as i know in-proc sessions state is lost after recompiling application and recycling application pool. App pool could be recycled if there is not enough memory or it's have regular restart time interval.