我将我的 .NET CORE 项目从 2.1 更新到 3.1,但我在 Startup 类中有一些错误 [英] I updated my .NET CORE project from 2.1 to 3.1, yet I have some errors in the class Startup
问题描述
我刚刚更新了我的 .NET CORE 版本.我已经更新了所有的使用,但是在添加默认标识时,我仍然在 satrtup 类中的 ConfigureServices 方法中出现错误.它只是给我一个错误,说‘IServiceCollection’不包含‘AddDefaultIdentity’的定义,也没有可访问的扩展方法‘AddDefaultIdentity...’".方法如下:
I just updated my version of .NET CORE. I already updated all the usings however I still have an error in the satrtup class, in the method ConfigureServices, when adding the default identity. It just gives me an error saying "'IServiceCollection' does not contain a definition for 'AddDefaultIdentity and no accessible extension method 'AddDefaultIdentity...'". Here is the method:
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 方法中也有错误.
I also have an error in the Configure method.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
//ERROR
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
//MORE CODE
}
我应该怎么做才能解决这个错误?
What should I do to solve this error?
推荐答案
这两个扩展方法已移入单独的 NuGet 包中,必须在 ASP.NET Core 3.0 及更高版本中显式引用:
Those two extension methods have moved into separate NuGet packages, which must be referenced explicitly in ASP.NET Core 3.0 and upwards:
方法 | 包装 |
---|---|
AddDefaultIdentity | Microsoft.AspNetCore.Identity.UI |
UseDatabaseErrorPage | Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore |
这篇关于我将我的 .NET CORE 项目从 2.1 更新到 3.1,但我在 Startup 类中有一些错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!