UserStore类在Asp.Net Identity中的用途是什么? [英] What is UserStore class is for in Asp.Net Identity?

查看:81
本文介绍了UserStore类在Asp.Net Identity中的用途是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上发现了一篇关于Asp.net身份的文章这里



他们有这个代码:





I came across a Article on Web for Asp.net Identity here.

They have this code:


public class AppUserManager : UserManager<AppUser> {

    public AppUserManager(IUserStore<AppUser> store)
     : base(store) {
     }

     public static AppUserManager Create(
     IdentityFactoryOptions<AppUserManager> options,
     IOwinContext context) {
         AppIdentityDbContext db = context.Get<AppIdentityDbContext>();
         AppUserManager manager = new AppUserManager(new UserStore<AppUser>(db));
         return manager;
     }
 } 





1.) AppUser 类是自定义类派生来自 IdentityUser 类。

2.) AppIdentityDbContext 派生自 IdentityDbContext 类。







这里我们正在创建一个自定义的AppManagerClass,它是从Asp.net的UserManager类中获得的。创建AppUserManager类实例的方法。



现在我想知道这两条线在做什么。





1.) The AppUser class is custom class deriving from the IdentityUser Class.
2.) The AppIdentityDbContext is deriving from the IdentityDbContext class.



Here we are creating a custom AppManagerClass which is derieved from UserManager class of Asp.net Identity this class has a method to create an instance of the AppUserManager class.

Now i want to know what these two lines are doing.

AppIdentityDbContext db = context.Get&lt;AppIdentityDbContext&gt;();
AppUserManager manager = new AppUserManager(new UserStore&lt;AppUser&gt;(db));



他们通过传递新的UserStore 类实例和 UserStore 来调用基本构造函数class要求传递 DbContext 类型。



但我无法从 UserStore 类中获得所需内容。



还请告诉我这行代码是什么回复。




They are Invoking the base contructor by passing in the new UserStore class instance and that UserStore class require DbContext type to be passed on.

But i am unable to get what is required from this UserStore class.

Also please tell me what this line of code is returning.

<pre>AppIdentityDbContext db = context.Get<AppIdentityDbContext>();

推荐答案

您必须在文章下提出此类问题或博客文章本身,它有助于作者保持他们的文章内容,以帮助读者,如果他有相同的问题,也可以帮助任何其他读者。在单独的论坛上提问不会对您,读者或任何人有所帮助。



ASP.NET Identity是一个基于完整接口的身份验证提供程序,其中有许多服务,存储,管理器,您可以根据自己的需要使用它们。然后,实体框架可以方便地处理应用程序的数据源。 ASP.NET不再仅需要SQL Server作为数据源,您可以使用任何数据源。为此,Entity Framework用于管理数据源。



UserStore [ ^ 是一个由MSDN很好描述的组件,

You must ask such questions under the article or blog post itself, it helps the authors to maintain their article contents to help the readers and can also help any other reader if he has the same question. Asking a question on a separate forum doesn't help you, readers or anyone.

ASP.NET Identity is a full interface based authentication provider, there are many services, stores, managers in it which you can use for your own needs. Entity Framework then comes in handy to handle the data sources for your application. ASP.NET no longer only requires SQL Server for data source, you can use any data source. For that sake, Entity Framework is used to manage the data sources.

The UserStore[^] is a component that is well described by MSDN as,
Quote:

代表一个实体支持IUserStore,IUserLoginStore,IUserClaimStore和IUserRoleStore的用户存储的框架实现。

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



您需要学习Identity框架,有很多东西无法在紧凑的答案中解释。您应该从MSDN开始学习,此处 [ ^ ]。



编辑



顾名思义(以及我在之前的内容中所说的),UserStore实际上是从中提取用户详细信息和记录的数据源。您可以定义自己的数据源。该类实际上存在于实体框架中。在您自己的应用程序中,您可以实现IUserStore接口并为您自己的应用程序添加其他功能。



有关ASP.NET中此对象的更深入讨论和概述,请阅读 http://www.asp.net/identity/overview/extensibility/overview-of- custom-storage-providers-for-aspnet-identity#userstore [ ^ ]。


这篇关于UserStore类在Asp.Net Identity中的用途是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆