Asp.net MVC Markdown 编辑器和 Html.Encode

发布于 2024-09-14 20:54:51 字数 253 浏览 3 评论 0原文

我在这里可能会误解,但根据我的理解,Markdown 编辑器会删除所有 html。

然后使用 markdown.Transform() 类型的方法,将数据库存储的 markdown 转换为带有 h​​1、p 等的 html。

使用 asp.net MVC,一般规则是 Html.Encode 一切。

但是,当使用 Markdown 编辑器看到 Html.Encoding 转换后的 markdown 会使生成的 html 无用时,这仍然适用吗?

I might be mis-understanding here but from my understanding a markdown editor strips out all html.

After then using a markdown.Transform() type of method this database stored markdown is converted into html with h1, p etc.

With asp.net MVC the general rule is Html.Encode everything.

But does this still apply when using a Markdown editor seeing as Html.Encoding the Transformed markdown will render the generated html useless?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

战皆罪 2024-09-21 20:54:51

HTML.Encode 一切都是针对潜在不安全的内容,通常是用户输入的任何内容,如果生成 HTML 并且输入可以信任(即通过剥离 HTML 的内容运行,通过 XSS 库运行),那么您可以安全地不对其进行编码。更明确地说,您可以返回 MvcHtmlString 而不是字符串。

HTML.Encode everything is for potentially unsafe content, usually anything user inputted, if HTML is generated and the input can be trusted (ie run through something that strips the HTML, is run through the XSS library) then you can safely not encode it. To be more explicit you can return an MvcHtmlString rather than a string.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文