5分钟后,MVC 4中的会话超时不足 [英] Session timeout owin in MVC 4 after 5 minutes

查看:170
本文介绍了5分钟后,MVC 4中的会话超时不足的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Owin上下文登录用户的MVC 4应用程序.记住是否选择了我,用户在5分钟后被踢出系统. Sessionstate设置为inProc,并且持续480分钟.这是startup.cs文件:

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;

    }

这是登录方法:

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

当用户不选中记住我"复选框时,我希望会话保持打开状态8个小时,否则应登录14天.但是,我似乎无法弄清楚.感谢您的帮助.

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.

推荐答案

请检查主机的iis版本,以及v == 8.5

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

将此代码行添加到web.config

add this lines of code to web.config

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

有关生成机器密钥的信息,请转到此链接 http://www.developerfusion.com/tools/generatemachinekey/

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

也许可以帮助某人.

这篇关于5分钟后,MVC 4中的会话超时不足的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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