asp.net - MVC 身份 ||禁用所有 cookie 和 "remember me"选项?

标签 asp.net asp.net-mvc asp.net-identity

我正在使用身份为 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/

相关文章:

asp.net - 使用 Javascript 设置 ModalPopupExtender "Y"属性

c# - 如何防止用户登录多个设备以及如何从之前的设备结束 session ?

c# - 我可以有一个名为 "View"的 ActionResult 吗

c# - ASP.NET MVC 4 - 以 HTML、JSON 或 XML 响应的正确方式

asp.net-mvc - 转换常规 MVC 站点以在 phonegap 中使用

c# - 在 MVC 中使用 Azure Active Directory 登录后如何添加和访问其他属性?

c# - 将连接字符串发送到 ApplicationDBContext

c# - WebService 中的 View 状态?这可能吗?

asp.net - 在 asp.net 开发服务器上调试 httpmodule

c# - SQL insert into not exists on multiple results