如何使用ASP.NET 3.0的身份没有实体框架 [英] How to use ASP.NET Identity 3.0 without Entity Framework
问题描述
我现在看到了ASP.NET身份的所有示例3.0使用实体框架来存储用户相关的数据。
All examples I've seen by now for ASP.NET Identity 3.0 use Entity Framework to store user-related data.
是否有不使用实体框架的例子,其中 ApplicationUser
类是不从 Microsoft.AspNet.Identity.EntityFramework.IdentityUser <派生/ code>?
Are there any example which does not use Entity Framework and where ApplicationUser
class is not derived from Microsoft.AspNet.Identity.EntityFramework.IdentityUser
?
在ASP.NET身份2.X它需要实施 IUSER
接口。似乎没有这样的接口了 - 所以我们不知道如何正确地定义用户
类。有关于这个问题几乎没有任何文档。
In ASP.NET Identity 2.x it was needed to implement IUser
interface. It seems there is not such interface now - so we're not sure how to define User
class correctly. There is almost no documentation on this subject.
第二个问题是与 AddIdentity
在 Startup.ConfigureServices
电话。这是pretty捆绑到特定的类从 Microsoft.AspNet.Identity.EntityFramework
命名空间,目前还不清楚如何在不这些类注册身份服务。
Second problem is with AddIdentity
call in Startup.ConfigureServices
. It's pretty tied to the particular classes from Microsoft.AspNet.Identity.EntityFramework
namespace and it's unclear how to register identity services without those classes.
推荐答案
我已经在我的项目实现了它,你必须实现的主要事情是UserStore和Rolestore的
I have implemented it in my project, the main things you have to implement is UserStore and RoleStore
我SiteUser和SiteRole类不从任何继承
my SiteUser and SiteRole classes do not inherit from anything
更主要的是让asp.net的身份加入了自己的服务之前添加自己的服务
the main thing is to add your own services before letting asp.net identity add its own services
services.TryAdd(ServiceDescriptor.Scoped<IUserStore<SiteUser>, UserStore<SiteUser>>());
services.TryAdd(ServiceDescriptor.Scoped<IUserPasswordStore<SiteUser>, UserStore<SiteUser>>());
services.TryAdd(ServiceDescriptor.Scoped<IUserEmailStore<SiteUser>, UserStore<SiteUser>>());
services.TryAdd(ServiceDescriptor.Scoped<IUserLoginStore<SiteUser>, UserStore<SiteUser>>());
services.TryAdd(ServiceDescriptor.Scoped<IUserRoleStore<SiteUser>, UserStore<SiteUser>>());
services.TryAdd(ServiceDescriptor.Scoped<IUserClaimStore<SiteUser>, UserStore<SiteUser>>());
services.TryAdd(ServiceDescriptor.Scoped<IUserPhoneNumberStore<SiteUser>, UserStore<SiteUser>>());
services.TryAdd(ServiceDescriptor.Scoped<IUserLockoutStore<SiteUser>, UserStore<SiteUser>>());
services.TryAdd(ServiceDescriptor.Scoped<IUserTwoFactorStore<SiteUser>, UserStore<SiteUser>>());
services.TryAdd(ServiceDescriptor.Scoped<IRoleStore<SiteRole>, RoleStore<SiteRole>>());
一些相同的interfsaces将在这里注册,但它会使用你的,如果在首次登记
some of the same interfsaces will be registered here but it will use yours if they are registered first
services.AddIdentity<SiteUser, SiteRole>();
这篇关于如何使用ASP.NET 3.0的身份没有实体框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!