ASP.Net MVC XDocument Html.Decode / Encode Help

时间:2022-11-12 00:11:48

Can someone explain the best way to handle this approach.

有人可以解释处理这种方法的最佳方法。

I am using TinyMCE editor. The information typed into this is loaded into a XDocument and then written to the database as a string by doing XDocument.ToString()

我正在使用TinyMCE编辑器。输入到此文件中的信息将加载到XDocument中,然后通过执行XDocument.ToString()将其作为字符串写入数据库

When I output the content to a webpage I load the string from the database into a XDocument, find the element and do a Html.Encode to write out.

当我将内容输出到网页时,我将数据库中的字符串加载到XDocument中,找到该元素并执行Html.Encode写出。

When the data gets put into the database it gets put in this format <p><em>TEST</em>999</p>

当数据被放入数据库时​​,它将以这种格式放入< p>< em> TEST< / em> 999< / p>

When I retrieve it from the XDocument and do a Html.Encode it actually writes to the page

当我从XDocument中检索它并执行Html.Encode时,它实际上写入页面

<p><em>TEST</em>999</p>

Obviously this is not what I want, it shouldn't write the HTML to the page for the user to see.

显然这不是我想要的,它不应该将HTML写入页面供用户查看。

What is the best approach to take. Do a Decode/Encode before it gets put into the database? The Decode/Encode methods confuse me cause I'm not sure what they actually do.

什么是最好的方法。在将Decode / Encode放入数据库之前进行解码/编码?解码/编码方法使我困惑,因为我不确定他们实际上做了什么。

Any help appreciated.

任何帮助赞赏。

1 个解决方案

#1


HTMLEncode is used to encode HTML content to show in browser. This means if you want to display <b> (not bold content) you can use HTML encode to display it. HTMLDecode decodes the string that encoded.

HTMLEncode用于编码要在浏览器中显示的HTML内容。这意味着如果要显示(非粗体内容),可以使用HTML编码来显示它。 HTMLDecode解码编码的字符串。

In your case, you don't need to encode or decode your content. Because TinyMCE editor gives the content in HTML format, and you want to display the HTML applied content.

在您的情况下,您不需要对内容进行编码或解码。因为TinyMCE编辑器以HTML格式提供内容,并且您希望显示HTML应用的内容。

#1


HTMLEncode is used to encode HTML content to show in browser. This means if you want to display <b> (not bold content) you can use HTML encode to display it. HTMLDecode decodes the string that encoded.

HTMLEncode用于编码要在浏览器中显示的HTML内容。这意味着如果要显示(非粗体内容),可以使用HTML编码来显示它。 HTMLDecode解码编码的字符串。

In your case, you don't need to encode or decode your content. Because TinyMCE editor gives the content in HTML format, and you want to display the HTML applied content.

在您的情况下,您不需要对内容进行编码或解码。因为TinyMCE编辑器以HTML格式提供内容,并且您希望显示HTML应用的内容。