【问题标题】:ASP.NET Forms authentication timeout expires too soonASP.NET Forms 身份验证超时过早过期
【发布时间】:2015-07-09 11:54:27
【问题描述】:

我已经阅读了很多示例,但我不知道为什么我的代码不起作用。这是我的web.config 代码在我的ASP.NET 项目中的一部分:

  <system.web>
      <authentication mode="Forms">
        <forms loginUrl="Panel/Login" timeout="525600" slidingExpiration="true" />
      </authentication>
      <compilation debug="true" targetFramework="4.5" />
      <httpRuntime targetFramework="4.5" maxRequestLength="1048576" />
  </system.web>

问题是,当我登录时,在我尝试请求某些内容时几分钟不活动后,我被导航到登录页面。即使我在登录页面中设置了持久性 cookie,也会发生这种情况!

我尝试增加和减少timeout 属性。

我试过slidingExpiration属性。

我试过cookieless属性。

它们都不起作用!

我在登录页面中使用此代码:

FormsAuthentication.SetAuthCookie(Username.Text, Remember_Me.Checked);

提前感谢。

【问题讨论】:

    标签: c# asp.net forms authentication


    【解决方案1】:

    您可以尝试将 machineKey 添加到您的代码中:

    <machineKey validationKey=”AutoGenerate”
    

    您可以在此处查看更多详细信息:

    http://blog.falafel.com/asp-net-forms-authentication-times-out-on-a-shared-host/

    或者这可能在帮助中:

    Asp.net forms authentication cookie not honoring timeout with IIS7

    【讨论】:

    • 我同意机器密钥。如果应用程序池回收了一个新的机器密钥,则会生成一个。使用 set machinekey 可能会有所帮助,但如果应用程序池在短时间内回收,则可能会出现另一个问题。您是否还在会话状态中存储任何可能很大的内容或使用任何可能占用资源的非托管代码?
    • 非常感谢!它帮助了我。但是现在的问题是当我选中“记住我”复选框时,我仍然在超时属性中提到了时间。我的意思是现在如果我选中复选框没有区别。我该怎么办???
    • 现在,如果用户选中了“记住我”复选框,我将设置 FormsAuthenticationTicket,如果他/她没有选中,我将使用 FormsAuthentication.SetAuthCookie。你帮了我很多。谢谢你:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-21
    • 2012-01-30
    • 1970-01-01
    • 2019-04-19
    相关资源
    最近更新 更多