加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – MVC标识||禁用所有cookie并“记住我”选项?

发布时间:2020-12-15 19:48:21 所属栏目:asp.Net 来源:网络整理
导读:我正在使用MVC 4和身份2.0,我在我的网站(开箱即用功能)“记住我”,我想禁用此选项,并在我的网站中有这两个选项之一: 1.用户每次使用我的网站时都需要登录(输入用户名和密码). 2.user每次都需要登录,但网站会记住他30分钟并且不会强迫他在该时间段内登录(在
我正在使用MVC 4和身份2.0,我在我的网站(开箱即用功能)“记住我”,我想禁用此选项,并在我的网站中有这两个选项之一:

1.用户每次使用我的网站时都需要登录(输入用户名和密码).

2.user每次都需要登录,但网站会记住他30分钟并且不会强迫他在该时间段内登录(在我们的情况下为30分钟).

我怎样才能完成这3件事?

禁用我只是注释登录页面中的复选框我认为它会做的伎俩:)

编辑:

当我设置这个:

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);

并从您的视图中删除此复选框.

要使Cookie在30分钟后过期,请在Auth.Config中将ExpireTimeSpan设置为30分钟

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,});

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读