Ter*_*ves 5 c# asp.net-core asp.net-core-3.1
我刚刚更新了我的 .NET CORE 版本。我已经更新了所有使用,但是在添加默认标识时,我仍然在 satrtup 类中的 ConfigureServices 方法中出现错误。它只是给我一个错误,说“‘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();
}
Run Code Online (Sandbox Code Playgroud)
我在 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
}
Run Code Online (Sandbox Code Playgroud)
我应该怎么做才能解决这个错误?
Kir*_*kin 10
这两个扩展方法已移入单独的 NuGet 包中,必须在 ASP.NET Core 3.0 及更高版本中显式引用:
| 方法 | 包裹 |
|---|---|
AddDefaultIdentity |
Microsoft.AspNetCore.Identity.UI |
UseDatabaseErrorPage |
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore |