ASP.Net Core 2.0中{AllowHtml]的替代是什么

时间:2018-01-30 05:07:10

标签: asp.net-mvc asp.net-core asp.net-core-mvc asp.net-core-2.0

我想在我的MVC Core 2.0应用程序中集成CKEditor,在之前的版本中我通过将[AllowHTML]数据注释添加到我的字符串属性来使用它。但在ASP.Net Core中,我找不到将HTML插入字符串输入的正确方法。

我在ASP.Net MVC 5中的代码

[AllowHtml]
[DataType(DataType.MultilineText)]
public string Profile { get; set; }

但在ASP.Net Core 2.0 [AllowHtml]无法正常工作。我在谷歌搜索但找不到正确的解决方案,除了这个链接https://docs.microsoft.com/en-us/aspnet/core/security/cross-site-scripting

[DataType(DataType.MultilineText)]
public string Profile { get; set; }

我真的遇到了这个问题,需要.Net专家的帮助,谢谢。

1 个答案:

答案 0 :(得分:1)

使用Asp.Net Core razor,您可以通过以下方式将原始html输出到页面中:

     @Html.Raw(theString)

我觉得有必要指出,您需要确保theString包含安全的HTML输出,以免它对XSS攻击敞开大门。