Where is HtmlEncode in Asp.NET 5

不羁的心 提交于 2019-12-04 01:17:36

HtmlEncoder in Microsoft.Extensions.WebEncoders.Core is just a wrapper around System.Text.Encodings.Web.HtmlEncoder to implement IHtmlEncoder interface (https://github.com/aspnet/HttpAbstractions/blob/release/src/Microsoft.Extensions.WebEncoders.Core/HtmlEncoder.cs).

You can take Microsoft.Extensions.WebEncoders.HtmlEncoder.Default and pass to WriteTo method.

From what I see in dev branch MVC moved to using System.Text.Encodings.Web.HtmlEncoder directly so you wan't need to use Microsoft.Extensions.WebEncoders.HtmlEncoder anymore in future.

Miroslav Holec

In ASP.NET Core RC2 you can find HtmlDecode in System.Net.WebUtility:

In your project.json import dependency system.net.utilities

"dependencies": {
    "System.Text.Encodings.Web": "4.0.0-rc2-24027"
}

As for RC1 update 1, here is how it is done:

using System.Text.Encodings.Web;

...

HtmlEncoder.Default.Encode("...");

Just use System.Net.WebUtility.HtmlEncode or decode as:

System.Net.WebUtility.HtmlEncode() System.Net.WebUtility.HtmlDecode()

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!