I'm using MVC 4 with identity 2.0 and i have in my site (out of the box feature) "Remember me" and i want to disable this option and have one of this two option in my site:
1.user will need to log in (enter username & password) every time he uses my site.
2.user will need to log in every time but the site will remember him for 30 min and not force him to do log-in in that time period(30 min in our situation).
How can i accomplish those 3 things ?
to disable i just comment the check box in the login page i think it will do the trick :)
EDIT:
When i set this :
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Logon/LogOn"),
ExpireTimeSpan = TimeSpan.FromMinutes(30),
});
Do i need to comment/delete this code from there:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
For disabling "Remember me" pass false
as the last parameter in
await userManager.SignInAsync(AuthenticationManager, user, false);
And remove this checkbox from your view.
To make cookie expire in 30 minutes, in your Auth.Config
set ExpireTimeSpan
to 30 minutes
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Logon/LogOn"),
ExpireTimeSpan = TimeSpan.FromMinutes(30),
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With