Session timeout owin in MVC 4 after 5 minutes

回眸只為那壹抹淺笑 提交于 2020-01-05 10:18:29

问题


I have an MVC 4 application which uses Owin context to login users. Remember me selected or not, users get kicked out of the system after 5 minutes. Sessionstate is set to be inProc, and it is for 480 minutes. Here is the startup.cs file:

  public void ConfigureAuth(IAppBuilder app)
  {
// Enable the application to use a cookie to store information for the signed in user
        // and to use a cookie to temporarily store information about a user logging in with a third party login provider
        // Configure the sign in cookie
        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Account/Login"),
            ExpireTimeSpan = TimeSpan.FromDays(14.0)
        });            
        app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

        AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.Name;

    }

Here is the signin method:

private void SignInAsync(string name, string role, bool isPersistent)
    {
        AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
        var claims = new List<Claim>();
        claims.Add(new Claim(ClaimTypes.Name, name));
        claims.Add(new Claim(ClaimTypes.Role, role));
        var identity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);
        AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent}, identity);
    }

I would like to keep the session open for 8 hours when users don't check the rememberme checkbox, otherwise they should be logged in for 14 days. However, I cannot seem to figure out. Any help is appreciated.


回答1:


please check iis version of your host and if v==8.5

add this lines of code to web.config

<machineKey   
validationKey=""
decryptionKey=""
validation="SHA1" decryption="AES"

for generate machinekey go to this link http://www.developerfusion.com/tools/generatemachinekey/

maybe it helps someone.



来源:https://stackoverflow.com/questions/35382590/session-timeout-owin-in-mvc-4-after-5-minutes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!