问题
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();
}
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?
回答1:
Those two extension methods have moved into separate NuGet packages, which must be referenced explicitly as of ASP.NET Core 3.0:
- For
AddDefaultIdentity
, add a reference to the Microsoft.AspNetCore.Identity.UI NuGet package. - For
UseDatabaseErrorPage
, add a reference to the Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore NuGet package.
来源:https://stackoverflow.com/questions/60659122/i-updated-my-net-core-project-from-2-1-to-3-1-yet-i-have-some-errors-in-the-cl