是否可以在没有 Entity Framework 和 Entity Framework 迁移的情况下使用 ASP.NET Identity?我的应用程序的其余部分将使用 Micro ORM 进行数据访问。但是,该应用程序正在使用内置的 ASP.NET Identity Individual User 帐户。
我的目标是仍然能够使用内置的 UserManager 和 LoginManager 类,并另外检索使用 Micro ORM 的用户列表,并消除与 EF/迁移有关的任何事情。这可能吗?看起来不像,因为原始数据库结构是通过应用初始迁移创建的。
如果有人有好的技术,请分享。
最佳答案
首先您需要创建一个自定义用户商店:
public class UserStore : IUserStore<IdentityUser>,
IUserClaimStore<IdentityUser>,
IUserLoginStore<IdentityUser>,
IUserRoleStore<IdentityUser>,
IUserPasswordStore<IdentityUser>,
IUserSecurityStampStore<IdentityUser>
{
// interface implementations not shown
}
然后需要将其注册到依赖注入(inject)容器中:
// Add identity types
services.AddIdentity<ApplicationUser, ApplicationRole>()
.AddDefaultTokenProviders();
// Identity Services
services.AddTransient<IUserStore<ApplicationUser>, CustomUserStore>();
services.AddTransient<IRoleStore<ApplicationRole>, CustomRoleStore>();
这是 documented here .
关于c# - 在没有 Entity Framework 和迁移的 ASP.NET Core MVC 应用程序中使用 ASP.NET Identity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44707518/