【问题标题】:Non-english characters in ASP.NET's Core View are being displayed as �ASP.NET Core 视图中的非英语字符显示为 �
【发布时间】:2019-02-25 21:13:31
【问题描述】:

我无法显示非英文字母,例如:

<h3>żąćń</h3> 因为它显示为����

我尝试添加

  • <meta charset="ISO-8859-1">
  • <meta charset="ISO-8859-2">
  • <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  • <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
  • <meta charset="UTF-8">

到页面布局中的head部分,它在html源代码视图中。

还有:

        services.Configure<WebEncoderOptions>(options =>
        {
            options.TextEncoderSettings = new TextEncoderSettings(UnicodeRanges.All);
        });

知道如何解决这个问题吗?

【问题讨论】:

  • 您是否在其他浏览器上尝试过该页面?
  • @juunas 刚刚在 firefox 和 chrome 上尝试过,但没有积极的结果
  • 也许您需要转义 html 字符?
  • 您是否尝试使用 utf8 编码保存您的 .cshtml? VS 默认不使用 UTF8
  • 你使用哪种css字体?

标签: c# html asp.net asp.net-mvc asp.net-core


【解决方案1】:

我认为您应该尝试查找以检查实际文件的文件格式(使用某些软件来读取/写入其内容,例如 notepad++

确保将其保存为编码为 UTF8

【讨论】:

    【解决方案2】:

    也许 HttpUtility.HtmlEncode 方法会进一步帮助您。

    我认为您需要做的是对 html 实体进行编码。

    https://docs.microsoft.com/en-us/dotnet/api/system.web.httputility.htmlencode

    【讨论】:

      猜你喜欢
      • 2012-01-02
      • 1970-01-01
      • 2011-06-20
      • 2010-09-17
      • 1970-01-01
      • 2011-05-08
      • 1970-01-01
      • 2012-10-18
      • 1970-01-01
      相关资源
      最近更新 更多