我正在使用身份为 2.0 的 MVC 4,并且在我的站点中(开箱即用功能)“记住我”,我想禁用此选项并在我的站点中使用以下两个选项之一:
1.用户每次使用我的网站时都需要登录(输入用户名和密码)。
2.用户每次都需要登录但是 该站点将记住他 30 分钟,并且不会强制他在该时间段内(在我们的情况下为 30 分钟)进行登录。
我怎样才能完成这三件事?
要禁用我只是评论登录页面中的复选框,我认为它可以解决问题:)
编辑:
当我设置这个时:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Logon/LogOn"),
ExpireTimeSpan = TimeSpan.FromMinutes(30),
});
我是否需要从那里注释/删除此代码:
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);
最佳答案
禁用“记住我”通行证 false
作为最后一个参数
await userManager.SignInAsync(AuthenticationManager, user, false);
并从您的 View 中删除此复选框。
要使 cookie 在 30 分钟后过期,请在您的
Auth.Config
套装ExpireTimeSpan
到 30 分钟app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Logon/LogOn"),
ExpireTimeSpan = TimeSpan.FromMinutes(30),
});
关于asp.net - MVC 身份 ||禁用所有 cookie 和 "remember me"选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25603049/