延长Asp.net身份验证cookie的生命周期

kam*_*001 2 asp.net cookies forms-authentication asp.net-authentication

我使用以下代码来设置身份验证cookie:

System.Web.Security.FormsAuthentication.SetAuthCookie(Profile.Email, true);
Run Code Online (Sandbox Code Playgroud)

我的问题是如何增加此身份验证cookie的生命周期?

Laz*_*rus 6

超时主要在web.config文件中设置,你可以在代码中完成,但我不建议.

这些是默认设置,您可以看到以分钟为单位指定的超时值.

<system.web>
  <authentication mode="Forms">
    <forms loginUrl="Login.aspx"
           protection="All"
           timeout="30"
           name=".ASPXAUTH" 
           path="/"
           requireSSL="false"
           slidingExpiration="true"
           defaultUrl="default.aspx"
           cookieless="UseDeviceProfile"
           enableCrossAppRedirects="false" />
  </authentication>
</system.web>
Run Code Online (Sandbox Code Playgroud)