ASP.NET身份会话超时 [英] ASP.NET Identity Session Timeout

查看:70
本文介绍了ASP.NET身份会话超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ASP.NET Identity.我想将会话超时设置为无限制或最大值.我已经尝试了一些方法,但是没有效果.注意:我使用共享主机. 谢谢.

I use ASP.NET Identity .. I want to set session timeout to unlimited or max value. I've tried something but it doesn't effect. Note: I use shared hosting. Thank you.

//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()))
                )
        }
    });
}

推荐答案

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

    app.UseCookieAuthentication(new CookieAuthenticationOptions
    {
        ExpireTimeSpan = TimeSpan.FromSeconds(30),
    });
}

这篇关于ASP.NET身份会话超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆