如何解决在Web层中向现有.NET Core项目添加身份
在Web层中,identity
文件夹中有2个类
public class ApplicationIdentityDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationIdentityDbContext(DbContextOptions<ApplicationIdentityDbContext> options) : base(options)
{
}
}
public class ApplicationUser : IdentityUser
{
public string FullName { get; set; }
}
我的创业公司是:
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; set; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationIdentityDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("IdentityConnection")));
services.AddIdentity<ApplicationUser,IdentityRole>()
.AddEntityFrameworkStores<ApplicationIdentityDbContext>()
.AddDefaultTokenProviders();
services.AddControllersWithViews();
services.AddScoped<IProductDal,EfCoreProductDal>();
services.AddScoped<IProductService,ProductManager>();
services.AddScoped<ICategoryDal,EfCoreCategoryDal>();
services.AddScoped<ICategoryService,CategoryManager>();
services.AddMvc().SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_0);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app,IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
SeedDatabase.Seed();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios,see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseAuthentication();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name:"adminProducts",pattern:"admin/products",defaults: new { controller = "Admin",action = "ProductList" });
endpoints.MapControllerRoute(
name: "adminProducts",pattern: "admin/products/{id?}",action = "EditProduct" });
endpoints.MapControllerRoute(
name: "products",pattern: "products/{category?}",defaults: new { controller = "Shop",action = "List" });
endpoints.MapControllerRoute(
name: "default",pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
尽管一切似乎都很好,但是当我尝试在命令行中的正确目录中创建迁移时,却出现此错误:
D:\ WebProgramlama \ ShopApp \ ShopApp.WebUI> dotnet ef迁移添加yy
无法创建类型为“ ApplicationIdentityDbContext”的对象。有关设计时支持的不同模式,请参见https://go.microsoft.com/fwlink/?linkid=851728
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。