我刚刚更新了.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();
}
我在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开始必须明确引用这些包:
AddDefaultIdentity
,添加对Microsoft.AspNetCore.Identity.UI NuGet包的引用。UseDatabaseErrorPage
,添加对Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore NuGet包的引用。本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句