加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

如何使用ASP.NET Identity 3.0没有Entity Framework

发布时间:2020-12-15 18:53:07 所属栏目:asp.Net 来源:网络整理
导读:我现在看到的所有例子为ASP.NET Identity 3.0使用Entity Framework来存储用户相关的数据。 有没有使用实体框架和其中ApplicationUser类不是从Microsoft.AspNet.Identity.EntityFramework.IdentityUser派生的任何示例? 在ASP.NET Identity 2.x中,需要实现IU
我现在看到的所有例子为ASP.NET Identity 3.0使用Entity Framework来存储用户相关的数据。

有没有使用实体框架和其中ApplicationUser类不是从Microsoft.AspNet.Identity.EntityFramework.IdentityUser派生的任何示例?

在ASP.NET Identity 2.x中,需要实现IUser接口。看来现在没有这样的接口 – 所以我们不知道如何正确定义User类。几乎没有关于这个主题的文档。

第二个问题是在Startup.ConfigureServices中使用AddIdentity调用。它非常依赖于来自Microsoft.AspNet.Identity.EntityFramework命名空间的特定类,并且不清楚如何注册身份服务没有这些类。

解决方法

我已经在我的项目中实现它,你必须实现的主要事情是UserStore和RoleStore

我的SiteUser和SiteRole类不继承任何东西

主要的是在添加自己的服务之前,让asp.net身份添加自己的服务

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将在这里注册,但它会使用你的,如果他们首先注册

services.AddIdentity<SiteUser,SiteRole>();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读