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

我现在看到的所有例子为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>();

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....