会话超时发生在网络配置中提到的时间之前
session time out happening before the time mentioned in webconfig
在 webconfig 中,我提到会话超时为 20 分钟
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" maxRequestLength="350000" enableVersionHeader="false"
maxQueryStringLength="3584" executionTimeout="600"/>
<sessionState mode="InProc" timeout="20"></sessionState>
<globalization culture="en-GB" />
</system.web>
但是该网站在 20 分钟的空闲时间之前正在注销。
我在代码中遗漏了什么吗?
由于session信息存储在in-memory(mode="InProc"
),如果重启应用域,所有session信息将被删除。如果您在开发时在本地观察到这一点,那么每次重新编译您的应用程序时,都会发生这种情况。如果您在 Web 服务器上观察到此行为,则 IIS 也可能会回收应用程序域。出于这个原因,您可能需要考虑其他一些 session state modes
,例如 StateServer
或 SQLServer
。
到目前为止,我已经谈到了 ASP.NET Session。但还有身份验证。由于您谈到用户是 logged-off,因此如果您使用表单身份验证,cookie 可能会过期。这由配置中的 <authentication>
标签控制:
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" protection="All" />
</authentication>
所以你也可以检查这个超时。
底线:不要将 ASP.NET Session 与 ASP.NET 表单身份验证混淆。
在 webconfig 中,我提到会话超时为 20 分钟
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" maxRequestLength="350000" enableVersionHeader="false"
maxQueryStringLength="3584" executionTimeout="600"/>
<sessionState mode="InProc" timeout="20"></sessionState>
<globalization culture="en-GB" />
</system.web>
但是该网站在 20 分钟的空闲时间之前正在注销。 我在代码中遗漏了什么吗?
由于session信息存储在in-memory(mode="InProc"
),如果重启应用域,所有session信息将被删除。如果您在开发时在本地观察到这一点,那么每次重新编译您的应用程序时,都会发生这种情况。如果您在 Web 服务器上观察到此行为,则 IIS 也可能会回收应用程序域。出于这个原因,您可能需要考虑其他一些 session state modes
,例如 StateServer
或 SQLServer
。
到目前为止,我已经谈到了 ASP.NET Session。但还有身份验证。由于您谈到用户是 logged-off,因此如果您使用表单身份验证,cookie 可能会过期。这由配置中的 <authentication>
标签控制:
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" protection="All" />
</authentication>
所以你也可以检查这个超时。
底线:不要将 ASP.NET Session 与 ASP.NET 表单身份验证混淆。