会话超时发生在webconfig中提到的时间之前

时间:2016-01-10 07:06:25

标签: asp.net-mvc asp.net-mvc-3 session

在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分钟之前正在退出。 我在代码中遗漏了什么?

1 个答案:

答案 0 :(得分:1)

由于会话信息存储在内存中(mode="InProc"),如果重新启动应用程序域,则将删除所有会话信息。如果您在开发过程中在本地观察到这一点,那么每次重新编译应用程序时,都会发生这种情况。如果您在Web服务器上发现此行为,IIS也可能会回收应用程序域。因此,您可能需要考虑StateServerSQLServer之类的其他session state modes

到目前为止,我已经讨论过ASP.NET Session。但也有认证。由于您谈到用户已注销,因此如果您使用表单身份验证,则Cookie可能会过期。这由配置中的<authentication>标记控制:

<authentication mode="Forms">
    <forms loginUrl="~/Account/Login" timeout="2880" protection="All" />
</authentication>

所以你也可以检查这个超时。

结论:不要将ASP.NET Session与ASP.NET Forms Authentication混淆。

相关问题