gpt4 book ai didi

asp.net - 如何在没有 Entity Framework 的情况下使用 ASP.NET Identity 3.0

转载 作者:行者123 更新时间:2023-12-03 08:49:54 24 4
gpt4 key购买 nike

关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。












想改进这个问题?将问题更新为 on-topic对于堆栈溢出。

6年前关闭。




Improve this question




我现在看到的所有 ASP.NET Identity 3.0 示例都使用 Entity Framework 来存储与用户相关的数据。

是否有任何不使用 Entity Framework 的示例以及 ApplicationUser类不是从 Microsoft.AspNet.Identity.EntityFramework.IdentityUser 派生的?

在 ASP.NET Identity 2.x 中需要实现 IUser界面。现在好像没有这样的接口(interface)-所以我们不确定如何定义User正确上课。几乎没有关于这个主题的文档。

第二个问题是 AddIdentity来电Startup.ConfigureServices .它与 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>>());

一些相同的接口(interface)将在此处注册,但如果它们先注册,它将使用您的接口(interface)
services.AddIdentity<SiteUser, SiteRole>();

关于asp.net - 如何在没有 Entity Framework 的情况下使用 ASP.NET Identity 3.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31795792/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com