我有一个MVC 4应用程序,它使用Owin上下文登录用户。记住我选择与否,用户在5分钟后被踢出系统。 Sessionstate设置为inProc,持续480分钟。这是startup.cs文件:
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);
}
当用户不检查rememberme复选框时,我想保持会话开放8小时,否则他们应该登录14天。但是,我似乎无法弄清楚。任何帮助表示赞赏。
答案 0 :(得分:1)
请检查主机的iis版本,如果v == 8.5
将这行代码添加到web.config
<machineKey
validationKey=""
decryptionKey=""
validation="SHA1" decryption="AES"
生成machinekey转到此链接 This is what I expect
也许对某人有帮助。