【问题标题】:What should i do if session logs out after "20" minutes in asp.net?如果会话在 asp.net 中“20”分钟后注销,我该怎么办?
【发布时间】:2014-04-01 08:24:45
【问题描述】:

我已经研究并为我的项目实施了一些代码,但仍然在 20 分钟后,我的会话退出并返回到我的登录页面。无论我在httpruntimesessionstateglobal.asax 上添加超时时间,还是在IIS 应用程序池中增加Idle Timeout,它似乎都不起作用。

web.config:

  <authentication mode="Forms">
      <forms name="__authcookie" loginUrl="LoginPage.aspx" timeout="60" protection="All" requireSSL="false" slidingExpiration="true" cookieless="UseDeviceProfile" enableCrossAppRedirects="false"/>
  </authentication>
  <sessionState mode="InProc" timeout="60" customProvider="AppFabricCacheSessionStoreProvider"></sessionState>
<membership>
  <providers>
    <clear />
    <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
  </providers>
</membership>
<profile>
  <providers>
    <clear />
    <add name="AppFabricCacheSessionStoreProvider" type="Microsoft.ApplicationServer.Caching.DataCacheSessionStoreProvider" cacheName="NamedCache1" sharedId="SharedApp"/>
    <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
  </providers>
</profile>

global.asax:

void Session_Start(object sender, EventArgs e)
        {
            // Code that runs when a new session is started
            Session.Timeout = 60;
        }

【问题讨论】:

    标签: c# asp.net visual-studio-2010


    【解决方案1】:

    尝试将此添加到您的 web.config 文件中

    <system.web>
        <authentication mode="Forms">
              <forms timeout="50"/>
        </authentication>
        <sessionState timeout="60"  />
    </system.web>
    

    此外,如果您不希望会话超时,您可能有兴趣阅读这篇关于 Avoid Prevent Session TimeOut In Asp.Net To Keep Alive 的文章

    【讨论】:

      【解决方案2】:

      可能不是会话超时,而是身份验证。使用&lt;authentication&gt; 元素(默认为.ASPXAUTH cookie)控制身份验证,这与会话(默认为Aspnet_SessionId cookie)不同。

      使用&lt;authentication&gt; 元素的timeout 属性。

      【讨论】:

        猜你喜欢
        • 2010-11-25
        • 2018-01-31
        • 1970-01-01
        • 1970-01-01
        • 2015-02-21
        • 2014-10-21
        • 1970-01-01
        • 2020-12-27
        • 1970-01-01
        相关资源
        最近更新 更多