ASP.NET 标识会话超时

Yar*_*icx 6 asp.net session asp.net-identity

我使用 ASP.NET Identity .. 我想将会话超时设置为无限制或最大值。我试过一些东西,但没有效果。注意:我使用共享主机。谢谢你。

//web.config
<system.web>
<customErrors mode="Off" />
<httpRuntime targetFramework="4.5" />
<authentication mode="Forms" />
<sessionState timeout="500000" />
</system.web>

//asp.identiyt config 
public void ConfigureAuth(IAppBuilder app)
{
    app.UseCookieAuthentication(new CookieAuthenticationOptions
    {
        AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
        ExpireTimeSpan = TimeSpan.FromDays(365),
        LoginPath = new PathString("/user/login"),
        Provider = new CookieAuthenticationProvider
        {
            OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser, int>
                (
                     validateInterval: TimeSpan.FromDays(365),
                     regenerateIdentityCallback: (manager, user) => user.GenerateUserIdentityAsync(manager),
                     getUserIdCallback: (id) => (Int32.Parse(id.GetUserId()))
                )
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

小智 6

public void ConfigureAuth(IAppBuilder app)
{            
    var sessionTimeout = 20; // 

    app.UseCookieAuthentication(new CookieAuthenticationOptions
    {
        ExpireTimeSpan = TimeSpan.FromSeconds(30),
    });
}
Run Code Online (Sandbox Code Playgroud)

  • *“您不能将会话超时设置为无限制”* **那** 将包含有效和相关信息。您发布的内容只是尝试 OP 已经在尝试的方法的另一种方式,这并不是他们想要的。 (2认同)