Asp.net mvc 在web层向现有.NET核心项目添加标识
在web层中,我在Asp.net mvc 在web层向现有.NET核心项目添加标识,asp.net-mvc,asp.net-core,asp.net-identity,identity,asp.net-core-identity,Asp.net Mvc,Asp.net Core,Asp.net Identity,Identity,Asp.net Core Identity,在web层中,我在identity文件夹中有两个类 public class ApplicationIdentityDbContext : IdentityDbContext<ApplicationUser> { public ApplicationIdentityDbContext(DbContextOptions<ApplicationIdentityDbContext> options) : base(options) { } } publ
identity
文件夹中有两个类
public class ApplicationIdentityDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationIdentityDbContext(DbContextOptions<ApplicationIdentityDbContext> options) : base(options)
{
}
}
public class ApplicationUser : IdentityUser
{
public string FullName { get; set; }
}
公共类ApplicationIdentityDbContext:IdentityDbContext
我用PMC成功地尝试了代码和迁移,请确保迁移路径中包含了ApplicationIdentityDbContext
。我确信ApplicationIdentityDbContext也包含在web层中。我右键单击web层,然后在文件资源管理器中选择打开文件夹,然后我在写迁移。我想可能是你上下文的位置不正确。如果我们使用默认生成的模板,则上下文将位于Data文件夹中,而不是Identity。我处理它,可能是因为我使用了一些旧版本的软件包,thaks for helpfull Comments Application Identity YDBContext。。。{}是无用的,可以中断迁移。
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?}",
defaults: new { controller = "Admin", 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?}");
});
}
}