且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么我失去我的会话变量?

更新时间:2023-11-27 23:48:28

有两方面的原因,这可能发生。 1)会话超时,或2)使用的是进行中会话状态。

There are two reasons this could be happening. 1) The session is timing out, or 2) you are using "In Process" session state.

如果用户在网页上的三十分钟,然后将值消失了,他们刷新或转到另一个页面,它可能是超时问题的下一次。你可以尝试增加的sessionState超时;但是,你可能会开始运行到下面描述的问题。如果你有决心用Session变量,你应该切换到不同的状态模式不是过程,这是默认的。

If the user sits on a page for thirty minutes, and then the value is gone the next time they refresh or go to another page, its likely a timeout problem. You could try increasing the sessionState timeout; however, you'll probably start running into the issue described below. If you are determined to use Session variables, you should probably switch to a different state mode than "in process" which is the default.

如果它不超时,你的价值丢失的原因是因为进行中会话状态消失时,应用程序池回收。这种情况可能有多种原因。你可能想改变你的会话状态模式状态服务器或SQL Server。这将让您的会话数据之间围绕应用程序池回收,但您需要在Web服务器上启用ASP.NET会话状态服务,如果你去的国家服务器的路由。

If it is not timing out, the reason your value is lost is because "In Process" session state, goes away when the App Pool recycles. This can happen for a variety of reasons. You probably want to change your session state mode to State Server or SQL Server. This will keep your session data around between app pool recycles, but you will need to enable the "ASP.NET Session State Service" on the web server if you go the State Server route.

有几个州的模式,每种模式不同的行为。你可以阅读他们这里MSDN上。

There are several state modes, each with different behaviors. You can read about them here on MSDN.