c# - FormsAuthentication Microst.AspNet.Identity.Owin.SignInManager.to authenticate 之间的区别

标签 c# asp.net asp.net-mvc authentication forms-authentication

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/

相关文章:

javascript - 如何在 MVC asp.net 中传递 LIST 以查看 JSON

c# - 任何人都知道如何使用 Array 中的逗号分隔列从字符串 Array 批量插入到 SQL

c# - 在 C# 中使用事件处理程序进行顶级异常处理

asp.net-mvc - 我的一些 asp mvc 4 包停止工作

asp.net - 尽管启用了 SSL,但获取 "Firefox can’ t 建立与本地主机服务器的连接

.net - 如何在 ViewBag 中传递变量列表

c# - 如何获取托管 asp.net 应用程序的计算机的 HostName、Ip

c# - ASP.NET 从 anchor 获取以 px 为单位的文本位置

asp.net - TreeView 控件呈现为 <div>,导致不需要的换行符

javascript - 如何在javascript中处理xml字符串