c# - 在没有 Entity Framework 和迁移的 ASP.NET Core MVC 应用程序中使用 ASP.NET Identity

标签 c# asp.net entity-framework asp.net-core asp.net-identity

是否可以在没有 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/

相关文章:

asp.net - CheckboxList 显示对齐?

asp.net - CSS 未应用于未经身份验证的 ASP.NET 页面

asp.net-mvc-3 - MVC3 : EF Code First and authentication

c# - 当前上下文 ASP.NET MVC5 中不存在名称 'Model'

c# - 基于行选择的Datagridview SelectionChanged事件

C# - MySQL 与 Microsoft SQL Server

c# - 隐藏部分面板C#

c# - 箱线图工具提示可见性

c# - AsNoTracking() 的全局设置?

c# - Entity Framework 属性隐藏