加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

ASP.NET标识会话超时

发布时间:2020-12-15 23:55:54 所属栏目:asp.Net 来源:网络整理
导读:我使用ASP.NET身份..我想将会话超时设置为无限或最大值.我尝试了一些东西,但它没有效果.注意:我使用共享主机. 谢谢. //web.configsystem.webcustomErrors mode="Off" /httpRuntime targetFramework="4.5" /authentication mode="Forms" /sessionState timeo
我使用ASP.NET身份..我想将会话超时设置为无限或最大值.我尝试了一些东西,但它没有效果.注意:我使用共享主机.
谢谢.
//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),});
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读