ASP.NET MVC 的默认项目模板带有一个名为 Microst.AspNet.Identity.Owin.SignInManager 的类。该类用于对用户进行身份验证
我不明白为什么我应该使用 SignInManager 而不是在 ASP.NET MVC 项目中使用简单的 FormsAuthentication。 SignInManager 有什么好处?
它是否根据 FormsAuthentication 以不同的方式进行身份验证?它比 FormsAuthentication 更安全吗?除了身份验证,我还能用 SignInManager 做什么?
SignInManager 和下面的代码有什么关系? SignInManager 是否使用以下设置?
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))
}
});
最佳答案
MembershipProvider 在 ASP.NET 2 中随 FormsAuthentication 一起提供。
ASP.NET Identity 在 ASP.NET 5 中随 SignInManager 一起提供。
ASP.NET Identity 是 MembershipProvider 的新版本。它提供了比旧版 MembershipProvider 更多的功能。
例如,
- Two-factor authentication
- 基于 token 的身份验证
- 与 MembershipProvider 相比,易于添加自定义属性
- 从 OWIN 上下文中获取 UserManager 的实例
如果您不需要所有这些功能,您可以坚持使用 FormsAuthentication,它可以在没有 MembershipProvider 的情况下使用。
关于c# - FormsAuthentication Microst.AspNet.Identity.Owin.SignInManager.to authenticate 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33085403/