问题
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