【问题标题】:How I can convert string into html inside of html如何在 html 中将字符串转换为 html
【发布时间】:2019-08-09 09:18:41
【问题描述】:

我得到了 html 标记的字符串,例如

<p>I want to trip/remove seconds from date time. 
I checked some solution but showing solution using 
format string like
</p> 
<pre><code class="language-c#"> 
DateTime datetime = DateTime.UtcNow; 
</code></pre>

作为我的 controlers 操作的结果 传递到 view。如何从 html 将其解码为 html 格式?或者也许我可以在我的 action 中生成 html 页面并将其附加到现有文档中?

【问题讨论】:

标签: c# html asp.net-core razor


【解决方案1】:

使用@Html.Raw():

@Html.Raw(htmlString)

我同意阿里的评论。

对未经处理的用户输入使用 HtmlHelper.Raw 存在安全风险。用户输入可能包含恶意 JavaScript 或其他漏洞。清理用户输入很困难。避免在用户输入中使用 HtmlHelper.Raw。

【讨论】:

  • 在我的情况下它接近警告情况 - 我需要在博客上呈现新帖子,但帖子只能由批准的用户添加,这会稍微降低危险。但是还有吗?还有其他方法可以围绕它构建吗?
猜你喜欢
  • 2015-12-03
  • 2014-03-12
  • 1970-01-01
  • 1970-01-01
  • 2014-08-29
  • 1970-01-01
  • 1970-01-01
  • 2012-11-07
  • 1970-01-01
相关资源
最近更新 更多