HtmlEncode在Asp.NET 5中在哪里

编程入门 行业动态 更新时间:2024-10-21 14:28:12
本文介绍了HtmlEncode在Asp.NET 5中在哪里的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个自定义的IHtmlHelper扩展方法,该方法使用TagBuilder并返回HtmlString.我不能再将tagBuiler.ToString()传递给HtmlString构造函数,因为它现在只返回类型名称.

I have a custom IHtmlHelper extension method that uses TagBuilder and returns an HtmlString. I can no longer pass tagBuiler.ToString() to the HtmlString constructor as that just returns the typename now.

我知道可以使用tabBuiler.WriteTo(TextWriter, IHtmlEncoder)方法,但是我不知道如何真正使用实现IHtmlEncoder的对象.我在System.Text.Encodings.Web和Microsoft.Framework.WebEncoders中都看到了编码器.但是两个命名空间中的类型似乎不能很好地配合使用.

I see I can use the tabBuiler.WriteTo(TextWriter, IHtmlEncoder) method but I don't know exactly how to get my hands on an object that implments IHtmlEncoder. I see encoders in both System.Text.Encodings.Web and Microsoft.Framework.WebEncoders. But the types in the two namespace don't seem to play well together.

推荐答案

HtmlEncoder只是System.Text.Encodings.Web.HtmlEncoder的包装,用于实现IHtmlEncoder接口( github/aspnet/HttpAbstractions/blob/release/src/Microsoft. Extensions.WebEncoders.Core/HtmlEncoder.cs ).

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

您可以采用Microsoft.Extensions.WebEncoders.HtmlEncoder.Default并传递给WriteTo方法.

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

根据我在dev分支中看到的内容,MVC转而直接使用System.Text.Encodings.Web.HtmlEncoder,因此您以后不再需要使用Microsoft.Extensions.WebEncoders.HtmlEncoder.

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.

更多推荐

HtmlEncode在Asp.NET 5中在哪里

本文发布于:2023-11-14 10:06:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586921.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:HtmlEncode   Asp   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!