I updated my .NET CORE project from 2.1 to 3.1, yet I have some errors in the class Startup

梦想的初衷 提交于 2020-12-04 02:25:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!