繁体   English   中英

Asp.net Identity如何验证身份验证Cookie?

[英]Asp.net Identity How Authentication Cookie getting validated?

net身份在我的MVC 5应用程序中运行良好。 但是在Asp.net身份系统中我不清楚的几件事。

  1. 如何在服务器上验证身份验证令牌(cookie)?
  2. 如果用户使用旧的身份验证cookie(即用户可能通过以前的登录获得了此身份),Asp.net将如何检测到它?

1.如何验证身份验证令牌(cookie)?
回答:您可以在实现此逻辑的App_Start文件夹中找到Startup.Auth.cs文件:

   app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Account/Login"),
            Provider = new CookieAuthenticationProvider
            {
                // Enables the application to validate the security stamp when the user logs in.
                // This is a security feature which is used when you change a password or add an external login to your account.  
                OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
                    validateInterval: TimeSpan.FromMinutes(30),
                    regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
            }
        });           

app.UseCookieAuthenticatin使您的应用程序也可以使用cookieAuthention并验证cookie,还可以创建自己的逻辑来验证cookie。

  1. 如果用户使用旧的身份验证cookie(即用户可能通过以前的登录获得了此身份),Asp.net将如何检测到它?
    回答:它会忽略过期的cookie,您可以使用以下代码在CookieAuthenticationOptions中定义cookie的过期时间:

    ExpireTimeSpan = TimeSpan.FromHours(1),

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM