C# 标识在.NET核心项目中不起作用
我创建了一个没有标识的.NET核心项目,然后尝试从scaffold添加标识。我的启动代码是:C# 标识在.NET核心项目中不起作用,c#,asp.net-core,asp.net-identity,C#,Asp.net Core,Asp.net Identity,我创建了一个没有标识的.NET核心项目,然后尝试从scaffold添加标识。我的启动代码是: public System.IServiceProvider ConfigureServices(IServiceCollection services) { services.AddDbContext<ProjectDbContext>(options => options.UseSqlServer( Configuration.Get
public System.IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ProjectDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<Microsoft.AspNetCore.Identity.IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ProjectDbContext>();
...
}
public System.IServiceProvider配置服务(IServiceCollection服务)
{
services.AddDbContext(选项=>
options.UseSqlServer(
GetConnectionString(“DefaultConnection”);
services.AddDefaultIdentity(options=>options.SignIn.RequireConfirmedAccount=true)
.AddEntityFrameworkStores();
...
}
但是,当调用标识表单时,该表单不起作用,且标题URL为:
我遗漏了什么?我不知道您的问题到底是什么,但如果您想手动添加标识,也许此代码对您有用,只需将其放在启动时配置服务类中即可:
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ProjectDbContext>()
.AddDefaultTokenProviders();
services.AddDbContext<ProjectDbContext>(options =>
option.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity()
.AddEntityFrameworkStores()
.AddDefaultTokenProviders();
services.AddDbContext(选项=>
option.UseSqlServer(Configuration.GetConnectionString(“DefaultConnection”));
并确保您的ProjectDbContext
继承自IdentityDbContext
,
对于
ApplicationUser
,如果您愿意,您可以使用IdentityUser
,或者您可以通过继承IdentityUser
自定义ApplicationUser
,并且在这两种方式上,不要向ProjectDbContext
添加任何DbSet
,Asp Core Identity将为您添加此代码。我不知道您到底有什么问题,但如果您想手动添加标识,也许此代码对您有效,只需将其放入启动时配置服务类中即可:
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ProjectDbContext>()
.AddDefaultTokenProviders();
services.AddDbContext<ProjectDbContext>(options =>
option.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity()
.AddEntityFrameworkStores()
.AddDefaultTokenProviders();
services.AddDbContext(选项=>
option.UseSqlServer(Configuration.GetConnectionString(“DefaultConnection”));
并确保您的ProjectDbContext
继承自IdentityDbContext
,
对于
ApplicationUser
,如果您愿意,您可以使用IdentityUser
,或者您可以通过继承IdentityUser
自定义ApplicationUser
,并且在这两种方式上,不要向ProjectDbContext
添加任何DbSet
,Asp Core Identity将为您添加此项。如果链接的解决方案无法解决此问题,则应Ping me。如果链接的解决方案无法解决此问题,则应Ping me。