我刚刚更新了 .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();
}
我的配置方法也有错误。
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 https://www.nuget.org/packages/Microsoft.AspNetCore.Identity.UI |
UseDatabaseErrorPage |
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore https://www.nuget.org/packages/Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore/ |
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)