我正在运行一个ASP.NET 2.0应用程序在IIS 6.0中。我希望会话超时时间为60分钟,而不是默认的20分钟。我已经完成以下操作:
- 在
web.config
文件中设置<sessionState timeout="60"></sessionState>
。 - 在IIS管理器/网站属性/ASP.NET配置设置中将会话超时时间设置为60分钟。
- 在应用程序池属性/性能中将空闲超时时间设置为60分钟。
但是我仍然在20分钟后遇到了会话超时问题。还有其他需要进行的操作吗?
我正在运行一个ASP.NET 2.0应用程序在IIS 6.0中。我希望会话超时时间为60分钟,而不是默认的20分钟。我已经完成以下操作:
web.config
文件中设置<sessionState timeout="60"></sessionState>
。但是我仍然在20分钟后遇到了会话超时问题。还有其他需要进行的操作吗?
你是否正在使用表单身份验证?
表单身份验证使用自己的超时值(默认为30分钟)。表单身份验证超时会将用户发送到登录页,但会保持会话仍处于活动状态。这可能看起来与会话超时时您的应用程序所呈现的行为相似,容易混淆。
<system.web>
<authentication mode="Forms">
<forms timeout="50"/>
</authentication>
<sessionState timeout="60" />
</system.web>
将表单超时时间设置为小于会话超时时间可以为用户提供一个窗口,在此期间重新登录而不会丢失任何会话数据。
我对web.config或IIS不太了解。但我相信你可以通过C#代码来完成它,例如
Session.Timeout = 60; // 60 is number of minutes
在web.config文件中使用以下代码块。这里默认的会话超时时间为80分钟。
<system.web>
<sessionState mode="InProc" cookieless="false" timeout="80" />
</system.web>
使用以下链接来实现带弹出警告消息的会话超时。
注意:上述示例是使用DevExpress弹出控件完成的,因此您需要自定义/替换DevExpress弹出控件为普通弹出控件。如果您正在使用DevExpress,则无需自定义。
在我的情况下,是应用程序池引起的。它被设置为在xx分钟空闲后重新启动。当我将其设置为不重新启动时,似乎使用了Web Config中的值。
您在machine.config中是否有任何可能生效的设置?在web.config中设置会话超时时间应该会覆盖IIS或machine.config中的任何设置,但是如果您的应用程序某个子文件夹中有一个web.config文件,则该设置将覆盖应用程序根目录中的设置。
另外,如果我没记错的话,IIS中的超时时间只影响.asp页面,而不是.aspx。您确定web.config中的会话代码是正确的吗?它应该类似于:
<sessionState
mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
stateNetworkTimeout="60"
sqlConnectionString="data source=127.0.0.1;Integrated Security=SSPI"
cookieless="false"
timeout="60"
/>
Startup.cs
的 void ConfigureServices
中更改会话超时值来进行更改:services.AddSession(options => options.IdleTimeout = TimeSpan.FromSeconds(42));
如果您想使用 appsettings.json
文件,可以这样做:
// Appsettings.json
"SessionOptions": {
"IdleTimeout": "00:30:00"
}
// Startup.cs
services.AddSession(options => options.IdleTimeout = TimeSpan.Parse(Config.GetSection("SessionOptions")["IdleTimeout"]));
https://usefulaspandcsharp.wordpress.com/tag/session-timeout/
<authentication mode="Forms">
<forms loginUrl="Login.aspx" name=".ASPXFORMSAUTH" timeout="60" slidingExpiration="true" />
</authentication>
<sessionState mode="InProc" timeout="60" />
<authentication mode="Forms">
<forms defaultUrl="Login.aspx" timeout="120"/>
</authentication>