如果使用默认的方式保存Session,有一点风吹草动都有可能造成Session的丢失(如ASP.NET的进程自动调整或重启,可以这么理解),使用SQLServer保存Session或者使用ASP.NET State Service服务保存状态都是不错的选择,上一个项目使用的是ASP.NET State Service,没有发现什么问题,保证在程序运行的时候,ASP.NET State Service服务是启动的就可以,如果发生更改了,手动重启一下这个服务就ok。我只是说了我的用法,可能有不对的地方(不保证全对)你可以详细的找一下关于ASP.NET State Service的内容。
不止10年,至少 15年吧。当时只是希望 asp.net 程序员不要连这个基本的知识都要引起争执,希望有个 asp.net 技术底线。可是没想到微软公司在 2006 年开始抛弃 asp.net 了,所以后来也就慢慢地懒得重复强调这个问题了。
这是一个 asp.net 编程基本知识。然而微软 asp.net 没有解决,相关的入门著作(许多事相互抄袭抄袭的水平)也总是把入门者在自己单机上的调试经验作为忽悠的目标。实际上这当然是当你把 asp.net 应用放到(特别是)租赁的网站空间上才会频繁发生的。
因为租赁的空间往往被管理员设置为每一个网站只能用更少的IIS连接数、更少的内存数、更短的时间.......然后系统就会自动释放一次 asp.net 进程。并且 asp.net 自己还会在许多文件稍加改变时自动释放(重启)。还有遇到严重点的 bug 时也会重启.....
asp.net 重启其实是个可接受的自我恢复措施。如果没有这个特性,也就不可能让一台那么破的服务器上能跑几百个根本没有怎么高强度长期测试的网站了。
但是既然有这个特性,那么负责设计开发 asp.net 应用的程序员就应该从一开始就知道要避免使用 Session 集合。(假设你使用 ASPNet SeateServer或者它的SQL Server方式序列化 Sesson,你要详细测试并保证所有对象都能反序列化,而这其实增加了困难)
刚刚 bluehost 给我回复的信息。。
您可以使用out-proc会话状态,将.NET会话状态模式设置为部分内的StateServer
这个不是很理解,麻烦大侠帮忙解决下。
您好,
We have set a time out value of 20 mins for IIS session service. Please note the application pool is recycled if it is idle for more than 5 mins. Thus, the inproc session is lost.
我们已经设置IIS会话超时时间为20mins,需要注意当空闲时间超过5mins时应用池会自动回收,因此inproc会话会随之丢失。
This is implemented in our servers to prevent abuse of resources. Note that changing the timeout value in the web.config file will not work.
以上的限制被应用在我司的主机来防止资源滥用。需要注意在web.config修改 timeout value是不会生效的。
Losing sessions happens whenever the application pool is recycled, and hence all session ids are dropped. There is limitation of 150 MB memory for the application pools.
当应用池回收的时候就会出现会话超时,因此所有的会话id都会掉线。win主机应用池限制的内存的150M,不能超过这一限制。
While it is understandable as to why set such a limit, problem is that limit is very low for .net websites that are poorly coded, since an empty website already needs 30 MB,
对于虚拟主机存在这种限制是很正常的,同时对于一些网站问题也就随之而来,那些代码优化程度不高的网站更是如此,因为一个空的网站就需要30MB,
so as soon as you add database and get traffic, it easily goes above 100 MB, causing the application pool to restart and session is lost having all your visitors logged out.
然后又加上数据库以及网站的访问,很容易超过100MB,一旦超过限制就会导致应用池回收、网站会话超时而跳出登录需要重新登录。
Below are some of the few things that one can look to do:
下面是一些供参考的解决方案:
Ways to optimize your websites to run under 150MB.
优化网站
SessionState = StateServer
By default, .net websites use in-proc session state to keep session information, in-proc sessions are kept in the application pool. So, to avoid depending on the application pool,
默认情况下,.net网站使用in-proc会话状态来保留会话信息,in-proc会话保存在应用程序池中。 所以,为了避免依赖于应用程序池,
you can use out-proc session state, to do so set the .NET session state mode to StateServer inside the section:
您可以使用out-proc会话状态,将.NET会话状态模式设置为部分内的StateServer:
-----
http://pastebin.com/hDghbjdS
------
Machine Key
If this still doesn't work (session keep resetting), means the StateServer mode still not being used. Then you can try adding a machineKey. Please check the following link for more details.
如果这仍然不起作用(会话保持重置),则表示StateServer模式仍未被使用。 然后你可以尝试添加一个machineKey。 请查看以下链接了解更多详情。
-----
http://pastebin.com/0QAqYt11
-----
如果您有任何问题,您可以随时直接回复该邮件获取更多的帮助,我们将在收到您的回复后尽快为您处理您的问题。
请勿重复提交您的问题,以免出现长时间无法处理您的问题或不同技术员检查后出现重复处理的情况。
在关闭状态下的工单,在系统收到您回复之后,系统将会再次开启该工单,因此您无需担心错过你提交的每一个问题。
感谢您对Bluehost的支持。
工单详细信息