如何在asp.net中增加会话超时? [英] how to increase session timeout in asp.net?
问题描述
我尝试使用以下代码来增加会话超时,但是没有用,
I tried following codes to increase session timeout, but no use,
代码是:
<sessionState mode="InProc" cookieless="true" timeout="60">
</sessionState>
也位于
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
Session.Timeout = 15;
}
推荐答案
您可以通过以下任意一种方式增加asp.net中的会话超时时间
You can increase the session time-out in asp.net in any one of the following ways
使用IIS版本7:
- 打开 IIS
- 从网站列表中选择您的网站
- 单击右侧的会话状态
- 现在在cookie设置下输入您的会话超时
- Open up IIS
- Select your website from the list of sites
- Click on Session state on the right
- Now enter your session timeout under the cookie settings
OR
Web.config: 打开您的web.config文件,并在 system.web 部分下添加以下内容:
Web.config : Open up your web.config file and under the system.web section add the following :
<sessionState timeout = "20" mode = "InProc" />
将20替换为您想要的任何数字.
Replace 20 with whatever number you wish.
OR
Global.asax文件: 在 Session_Start 方法下,将会话的 timeout 属性设置为所需的值,例如
Global.asax file : Under the Session_Start method, set the timeout property of the session to the required value like this
Session.Timeout = "20";
注意::如果您要同时在IIS和web.config中设置会话超时,则IIS中的会话超时将覆盖web.config中的会话超时
Note : If you are setting a session timeout in both IIS as well as web.config, then the one in IIS will override the one in web.config
希望这会有所帮助!
这篇关于如何在asp.net中增加会话超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!