c# - 从.NET Core 2.1降级到.NET 4.7.1时如何使用IApplicationBuilder和IServiceCollection?

标签 c# asp.net asp.net-core extension-methods downgrade

我必须将我的项目从 .NET Core 2.1 更改为 .NET 4.7.1,并且修复了几乎所有错误,除了以下仍然无法解决的错误

  • 'IApplicationBuilder' does not contain a definition for 'UseHsts' and no extension method 'UseHsts' accepting a first argument of type 'IApplicationBuilder' could be found (are you missing a using directive or an assembly reference?)

  • 'IApplicationBuilder' does not contain a definition for 'UseAuthentication' and no extension method 'UseAuthentication' accepting a first argument of type 'IApplicationBuilder' could be found (are you missing a using directive or an assembly reference?)

  • 'IApplicationBuilder' does not contain a definition for 'UseCookiePolicy' and no extension method 'UseCookiePolicy' accepting a first argument of type 'IApplicationBuilder' could be found (are you missing a using directive or an assembly reference?)

  • 'IApplicationBuilder' does not contain a definition for 'UseHttpsRedirection' and no extension method 'UseHttpsRedirection' accepting a first argument of type 'IApplicationBuilder' could be found (are you missing a using directive or an assembly reference?)

  • 'IApplicationBuilder' does not contain a definition for 'UseSession' and no extension method 'UseSession' accepting a first argument of type 'IApplicationBuilder' could be found (are you missing a using directive or an assembly reference?)

  • 'IApplicationBuilder' does not contain a definition for 'UseStaticFiles' and no extension method 'UseStaticFiles' accepting a first argument of type 'IApplicationBuilder' could be found (are you missing a using directive or an assembly reference?)

  • 'IServiceCollection' does not contain a definition for 'AddAuthentication' and no extension method 'AddAuthentication' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?)

  • 'IServiceCollection' does not contain a definition for 'AddSession' and no extension method 'AddSession' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?)

我正在使用 Microsoft.AspNetCore.BuilderMicrosoft.Extensions.DependencyInjection。我还需要使用/安装/添加什么才能使 IApplicationBuilderIServiceCollection 正常工作?

在我的 WebApi.csproj 文件中,我将目标框架从 netcoreapp2.1 更改为 net471。

旧:

<PropertyGroup>
  <TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

新:

<PropertyGroup>
  <TargetFramework>net471</TargetFramework>
</PropertyGroup>

最佳答案

按照 Rik 的回答,我搜索了更多包,发现我必须添加以下所有 NuGet 包:

  • Microsoft.AspNetCore.Authentication
  • Microsoft.AspNetCore.Session
  • Microsoft.AspNetCore.HttpsPolicy
  • Microsoft.AspNetCore.CookiePolicy
  • Microsoft.AspNetCore.StaticFiles

执行此操作后,我不再收到错误消息。

关于c# - 从.NET Core 2.1降级到.NET 4.7.1时如何使用IApplicationBuilder和IServiceCollection?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51553024/

相关文章:

java - 将 C# DateTime 转换为 GregorianCalendar 日期

c# - 使用时出现运行时错误和程序退出 - 使用 C# 进行异步和等待

c# - 如何以编程方式安装字体

asp.net - ASP.NET Identity session cookie 的安全性如何?

c# - WCF:从多行返回单行

asp.net-core - ReactJS.net 无法调试

c# - .Net 中是否有内置的扑克牌库?

javascript - 如何使用自动回发进行计算以避免屏幕闪烁

c# - 如何在服务器端 blazor 中存储 session 数据

c# - 身份 View 在哪里?