FormsAuthentication Microst.AspNet.Identity.Owin.SignInManager.to之间的区别

时间:2015-10-12 15:59:05

标签: 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))
    }
}); 

3 个答案:

答案 0 :(得分:6)

MembershipProvider 在ASP.NET 2中附带 FormsAuthentication

在ASP.NET 5中

ASP.NET标识附带 SignInManager

ASP.NET Identity是MembershipProvider的新版本。它提供了比传统MembershipProvider更多的功能。

例如,

  • Two-factor authentication
  • 基于令牌的身份验证
  • 与MembershipProvider相比,易于添加的自定义属性
  • 从OWIN上下文中获取UserManager的实例

如果您不需要所有这些功能,可以坚持使用 FormsAuthentication ,无需 MembershipProvider 即可使用。

答案 1 :(得分:2)

Forms Authentication是ASP.NET的身份验证框架的旧版本。反对使用表单身份验证的一个非常可靠的原因是it is deprecated

最新版本的Visual Studio中ASP.NET MVC的默认模板具有ASP.NET Identity Framework的实现,因此使用equals()。我相信使用ASP.NET身份的一个主要优点是它可以作为OWIN中间件托管,这意味着它不依赖于SignInManager,因此不依赖于您的Web应用程序。

答案 2 :(得分:0)

OWIN的想法是与平台无关。它是ASP.NET应用程序和运行它的平台之间的“中间件”。表单身份验证是为IIS上的ASP.NET构建的。 OWIN可以使用其他提供商,例如Google和Facebook。

看看这篇文章:https://www.tektutorialshub.com/owin/introduction-to-owin/