Kam*_*il 7 c# asp.net-identity asp.net-core asp.net-core-identity 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
}
Run Code Online (Sandbox Code Playgroud)
然后注入它:
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
}
Run Code Online (Sandbox Code Playgroud)
它被记录在官方文档中。
归档时间: |
|
查看次数: |
3154 次 |
最近记录: |