我有一个脑筋急转弯(阅读:“一周”)。我不知道如何在我的web项目中实现.Net核心标识。
我有WebAPI (剃刀核心3.1)项目和.NET项目(剃刀页面)。Web项目的目的是要与所有的数据库进行通信,WThe项目应该只用来连接到WebAPI并显示数据。
在Web项目中,我搭建了身份脚手架,并获得了注册、登录和注销页面。但是,搭建会创建新的DatabaseContext并以这种方式连接到数据库。
我想要的是实现它来连接到我的WebAPI并调用我的UserController端点。
请谁给我指个方向好吗?
发布于 2020-01-16 08:05:01
这个解决方案对我很有效:
我添加了一个新的UserStore。创建了新的类: ApplicationUserStore,并实现了接口IUserStore、IUserPasswordStore、IUserEmailStore。
public class ApplicationUserStore : IUserStore<IdentityUser>, IUserPasswordStore<IdentityUser>, IUserEmailStore<IdentityUser>
{}在IdentityHostingStartup.cs中,我删除了脚手架上下文:
services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationWebContext>();并添加了我的商店而不是它:
public class IdentityHostingStartup : IHostingStartup
{
public void Configure(IWebHostBuilder builder)
{
builder.ConfigureServices((context, services) => {
services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddUserStore<ApplicationUserStore>();
});
}
}发布于 2020-01-15 08:13:25
您的数据库上下文需要从以下类继承。
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
public class MyContext : IdentityDbContext<ApplicationUser, ApplicationRole, int, ApplicationUserClaim, ApplicationUserRole, ApplicationUserLogin, ApplicationRoleClaim, ApplicationUserToken>
{
public MyContext (DbContextOptions<MyContext > options)
: base(options)
{
}
}https://stackoverflow.com/questions/59743509
复制相似问题