简体   繁体   English

ASP.NET Core MVC Web应用程序中的HTML编码问题

[英]Issues with HTML Encoding in ASP.NET Core MVC web application

I just started at a new job as a senior .NET developer, and have run into a very puzzling issue with the package System.Text.Encodings.Web. 我刚开始担任.NET高级开发人员的新工作,但遇到了一个非常令人困惑的问题,即System.Text.Encodings.Web软件包。

The project is in .NET Framework 4.6.1 该项目位于.NET Framework 4.6.1中

The package is showing in the NUGET PACKAGE MANAGER as Installed version 4.5.0, however, the using statement in a .CS file that is trying to use the HtmlEncoder is showing an error with the error text "The type or namespace 'Encodings' does not exist in the namespace 'System.Text'. Are you missing an assembly reference?" 该软件包在NUGET PACKAGE MANAGER中显示为已安装版本4.5.0,但是,尝试使用HtmlEncoder的.CS文件中的using语句显示错误,错误文本为“ The type or namespace'Encodings'名称空间'System.Text'中不存在。是否缺少程序集引用?”

It also says after trying to build, another error, "The type HtmlEncoder is defined in an assembly that is not referenced, You must add a reference to assembly 'System.Text.Encodings.Web, version=4.0.3, Culture=neutral, and then a public key token after that." 它还表示尝试构建后出现另一个错误,“在未引用的程序集中定义了HtmlEncoder类型,您必须添加对程序集'System.Text.Encodings.Web的引用,版本= 4.0.3,Culture = neutral ,然后是一个公共密钥令牌。”

I tried several different things but none of them worked. 我尝试了几种不同的方法,但是没有一种起作用。

In my case, I had the same problem in a NUnitTest project which referenced the main project (both netcorapp2.1). 就我而言,我在引用主项目(均为netcorapp2.1)的NUnitTest项目中遇到了相同的问题。

I have solved the problem by copying the below Package References from the main project into the test project (.csproj files): 我已经通过将以下软件包引用从主项目复制到测试项目(.csproj文件)中来解决了该问题:

<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET Core MVC Web API 部署问题 - ASP.NET Core MVC Web API deployment issues ASP.Net Core MVC Web 应用程序角色管理 - ASP.Net Core MVC Web application roles management 将ASP.NET MVC Core应用程序的[部分]发布到Web主机 - Publishing [part] of ASP.NET MVC Core application to web host ASP.Net Core MVC路由问题 - ASP.Net Core MVC Route issues ASP.NET MVC Razor无法编码html - Asp.net MVC Razor not encoding html 将文件从 ASP.NET MVC 4.6 应用程序发布到 ASP.NET Core Web API - Posting a file from ASP.NET MVC 4.6 application to ASP.NET Core Web API 我可以将 ASP.NET Core MVC 添加到现有的 ASP.NET Web Z645024253191A381C36Z83CAE8 - Can I add ASP.NET Core MVC to existing ASP.NET Web Forms Application ASP.net Core 2.1 MVC验证标签帮助器-输出HTML(即停止HTML编码) - ASP.net Core 2.1 MVC Validation Tag Helper - output HTML (ie stop HTML Encoding) ASP.NET Core Web Application(.NET Framework)项目模板缺少System.Web.MVC dll - ASP.NET Core Web Application (.NET Framework) project template is missing System.Web.MVC dll ASP.Net核心Web应用程序(.Net Framework)发布EF Code First方法 - ASP.Net Core Web Application(.Net Framework) issues EF Code First approach
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM