What is the difference in the use of UserStore and UserManager in Asp.Net Identtity?

前端 未结 3 1000
春和景丽
春和景丽 2020-12-23 21:03

I\'m very new to Asp.Net Identity and please bear with me if this question seems silly. So, when I read the definition for UserStore class and UserManager class in Microsoft

3条回答
  •  旧时难觅i
    2020-12-23 21:51

    Identity is based on two primary blocks in ASP.NET Identity. There is an authentication manager which takes on the form of the UserManager class. There is also the store manager which is an instance of UserStore.

    Difference?

    The UserStore object is injected into authentication manager which is used to identify and authenticate the UserStore identity. The UserManager reference acts as the authenticator for the UserStore identity.

    Important Details

    ASP.NET Identity is based on the newest Open Web Interface. This means that that [typically], the IAuthenticationManager interface as declared in Microsoft.Owin.Security: Linked here, the authenticator injected into the UserManager class and controller and basically every operation that involves an authentication step.

    In the following:

    private async Task SignInAsync(ApplicationUser user, bool isPersistent)
    {
        var identity = await UserManager.CreateIdentityAsync(user,
        DefaultAuthenticationTypes.ApplicationCookie);
        AuthenticationManager.SignIn(new AuthenticationProperties() {
        IsPersistent = isPersistent }, identity);
    }
    

    We can notice the UserManager authentication manager being used to check the "UserStore" application user against the identity of the authentication manager. Snippet taken from blog.

    Conclusion The UserManager is the essentially the domain logic of your ASP.NET Identity. The controller you use to handle a "login" or "identification" is passed in by a UserStore, which as MSDN: Userstore depicts...

    Represents an Entity Framework implementation of a user store that supports IUserStore, IUserLoginStore, IUserClaimStore and IUserRoleStore.

    Once the UserStore has all necessary fields to be qualified as an identity and you have qualified the UserManager as the authentication manager, and a method of storing the context...aka IdentityDbContext or some other method of storing the values in SQL (If used), you will have a Identity system capable of supporting logins.

提交回复
热议问题