Can anyone show me an example of how to HTML encode text with the HtmlEncoder
class in the System.Text.Encodings.Web
namespace?
任何人都可以向我展示如何使用System.Text.Encodings.Web命名空间中的HtmlEncoder类对文本进行HTML编码的示例吗?
I'm converting an ASP.NET Core RC1 project to RC2. In the RC1 project I'm using the HtmlEncoder
class in the Microsoft.Extensions.WebEncoders
namespace. But there is no RC2 update for that.
我正在将ASP.NET Core RC1项目转换为RC2。在RC1项目中,我在Microsoft.Extensions.WebEncoders命名空间中使用HtmlEncoder类。但是没有RC2更新。
According to this GitHub post Microsoft.Extensions.WebEncoders
has been moved to System.Text.Encodings.Web
. But the HtmlEncoder
class in this new namespace is an abstract class and I can't find an implementation of it.
根据这个GitHub帖子,Microsoft.Extensions.WebEncoders已被移动到System.Text.Encodings.Web。但是这个新命名空间中的HtmlEncoder类是一个抽象类,我找不到它的实现。
1 个解决方案
#1
8
It's got a few static methods to build encoders now.
现在有一些静态方法来构建编码器。
Here's a simple example:
这是一个简单的例子:
var value = "Hello<br> world";
var encoder = HtmlEncoder.Default;
var result = encoder.Encode(value); // "Hello<br> world"
Other methods include:
其他方法包括:
public static HtmlEncoder Create(TextEncoderSettings settings);
public static HtmlEncoder Create(params UnicodeRange[] allowedRanges);
#1
8
It's got a few static methods to build encoders now.
现在有一些静态方法来构建编码器。
Here's a simple example:
这是一个简单的例子:
var value = "Hello<br> world";
var encoder = HtmlEncoder.Default;
var result = encoder.Encode(value); // "Hello<br> world"
Other methods include:
其他方法包括:
public static HtmlEncoder Create(TextEncoderSettings settings);
public static HtmlEncoder Create(params UnicodeRange[] allowedRanges);