我将.NET CORE项目从2.1更新到3.1,但是在启动类中出现了一些错误 [英] I updated my .NET CORE project from 2.1 to 3.1, yet I have some errors in the class Startup

查看:63
本文介绍了我将.NET CORE项目从2.1更新到3.1,但是在启动类中出现了一些错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚更新了.NET CORE的版本.我已经更新了所有用法,但是在添加默认标识时,在satrtup类中的ConfigureServices方法中仍然存在错误.它只是给我一个错误,指出'IServiceCollection'不包含'AddDefaultIdentity的定义,并且没有可访问的扩展方法'AddDefaultIdentity ...'".方法如下:

  public void ConfigureServices(IServiceCollection服务){services.Configure< CookiePolicyOptions>(options =>{//此lambda决定对于给定的请求是否需要用户同意非必要的cookie.options.CheckConsentNeeded =上下文=>真的;options.MinimumSameSitePolicy = SameSiteMode.None;});services.AddDbContext< ApplicationDbContext>(options =>options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))));//错误services.AddDefaultIdentity< IdentityUser>().AddEntityFrameworkStores< ApplicationDbContext>();services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);//信号Rservices.AddSignalR();} 

Configure方法也有错误.

  public void配置(IApplicationBuilder应用程序,IHostingEnvironment env){如果(env.IsDevelopment()){app.UseDeveloperExceptionPage();//错误app.UseDatabaseErrorPage();}别的{app.UseExceptionHandler("/Home/Error");app.UseHsts();}//更多代码} 

我该怎么办才能解决此错误?

解决方案

这两种扩展方法已移到单独的NuGet程序包中,从ASP.NET Core 3.0开始必须明确引用:

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?

解决方案

Those two extension methods have moved into separate NuGet packages, which must be referenced explicitly as of ASP.NET Core 3.0:

这篇关于我将.NET CORE项目从2.1更新到3.1,但是在启动类中出现了一些错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆