html禁止转义net mvc,停止使用HTML Unicode转义的ASP.NET Core 2 MVC的剃刀引擎?

通常,创建一个默认的ASP.NET Core 2 MVC项目,然后稍微修改一下操作:

public IActionResult About()

{

ViewData["Message"] = "This is Chinese[中文]";

return View();

}

这是视图(About.cshtml):

@ViewData["Message"]

这也是中文

这是浏览器中的输出结果:

This is Chinese[中文]

这也是中文

我发现以“ @”符号呈现的中文文本是html unicode转义的.问题是如何停止“ @”符号以使我的文字转义?

解决方法:

By default encoders use a safe list limited to the Basic Latin Unicode

range and encode all characters outside of that range as their

character code equivalents. This behavior also affects Razor TagHelper

and HtmlHelper rendering as it will use the encoders to output your

strings.

本文还提供了自定义默认html编码器的正确方法.将以下注册添加到Startup.ConfigureServices方法:

services.AddSingleton(

HtmlEncoder.Create(allowedRanges: new[] { UnicodeRanges.BasicLatin,

UnicodeRanges.CjkUnifiedIdeographs }));

这是此调整后的结果html代码:

This is Chinese[中文]

这也是中文

标签:asp-net-core,asp-net-core-mvc,asp-net-core-2-0,c

来源: https://codeday.me/bug/20191109/2012224.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值