c# - 如何在没有 EF Core 的情况下在 ASP .NET Core 3.1 中使用身份?
问题描述
我在 ASP.NET Core 3.1 中有一个项目,我想在我的应用程序中实现 Identity。我找到了很多关于 EF Core 的示例,但我使用的是 LinqConnect (Devart) 而不是 EF Core 和数据库 - SQL Server。我想知道如何以简单的方式为我的项目实现身份。
解决方案
基本上您需要做的就是创建您的自定义用户存储。
public class CustomUserStore : IUserStore<IdentityUser>,
IUserClaimStore<IdentityUser>,
IUserLoginStore<IdentityUser>,
IUserRoleStore<IdentityUser>,
IUserPasswordStore<IdentityUser>,
IUserSecurityStampStore<IdentityUser>
{
// interface implementations not shown
}
然后注入它:
public void ConfigureServices(IServiceCollection services)
{
// Add identity types
services.AddIdentity<ApplicationUser, ApplicationRole>()
.AddDefaultTokenProviders();
// Identity Services
services.AddTransient<IUserStore<ApplicationUser>, CustomUserStore>();
string connectionString = Configuration.GetConnectionString("DefaultConnection");
services.AddTransient<SqlConnection>(e => new SqlConnection(connectionString));
services.AddTransient<DapperUsersTable>();
// additional configuration
}
它记录在官方文档中。
推荐阅读
- r - 将具有 NA 的行删除到特定的列和条件中
- python - 从实例属性动态继承所有 Python 魔术方法
- javascript - 来自模板对象的对象构造函数
- django - Django - 获取查询集中的字段列表
- database - 我如何在我的火力库中注入新数据,制作我自己的信息帖子
- javascript - setState 不会更新 React 时钟
- bazel - Bazel 用于带有“bootstrap->configure->make”构建的软件包?
- r - 增加 ifelse True 计数并写入列
- html - 我可以使用 css 添加额外的列表项元素吗?
- angular - 材料表:在哪里放置数据源初始化以使用路由器出口保存组件状态