我将我的 .NET CORE 项目从 2.1 更新到 3.1,但我在 class 启动中有一些错误
I updated my .NET CORE project from 2.1 to 3.1, yet I have some errors in the class Startup
我刚刚更新了我的 .NET CORE 版本。我已经更新了所有的用法,但是在添加默认身份时,方法 ConfigureServices 中的 satrtup class 仍然有错误。它只是给我一个错误,说“'IServiceCollection' 不包含 'AddDefaultIdentity 的定义并且没有可访问的扩展方法 'AddDefaultIdentity...'”。这是方法:
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
//ERROR
services.AddDefaultIdentity<IdentityUser>()
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
//SIGNAL R
services.AddSignalR();
}
我的Configure方法也有错误
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
//ERROR
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
//MORE CODE
}
我应该怎么做才能解决这个错误?
这两个扩展方法已移动到单独的 NuGet 包中,必须在 ASP.NET Core 3.0 及更高版本中明确引用:
Method
Package
AddDefaultIdentity
Microsoft.AspNetCore.Identity.UI
UseDatabaseErrorPage
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore
我刚刚更新了我的 .NET CORE 版本。我已经更新了所有的用法,但是在添加默认身份时,方法 ConfigureServices 中的 satrtup class 仍然有错误。它只是给我一个错误,说“'IServiceCollection' 不包含 'AddDefaultIdentity 的定义并且没有可访问的扩展方法 'AddDefaultIdentity...'”。这是方法:
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
//ERROR
services.AddDefaultIdentity<IdentityUser>()
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
//SIGNAL R
services.AddSignalR();
}
我的Configure方法也有错误
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
//ERROR
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
//MORE CODE
}
我应该怎么做才能解决这个错误?
这两个扩展方法已移动到单独的 NuGet 包中,必须在 ASP.NET Core 3.0 及更高版本中明确引用:
Method | Package |
---|---|
AddDefaultIdentity |
Microsoft.AspNetCore.Identity.UI |
UseDatabaseErrorPage |
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore |