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

Sha*_*ikh 7 asp.net-mvc asp.net-core-mvc asp.net-core asp.net-core-2.0

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

我在 ASP.Net MVC 5 中的代码

[AllowHtml]
[DataType(DataType.MultilineText)]
public string Profile { get; set; }
Run Code Online (Sandbox Code Playgroud)

但在 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; }
Run Code Online (Sandbox Code Playgroud)

我真的被这个问题困住了,需要 .Net 专家的帮助,谢谢。

Ron*_*n C 1

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

     @Html.Raw(theString)
Run Code Online (Sandbox Code Playgroud)

我觉得有必要指出,您需要确保theString包含安全的 HTML 来输出,这样就不会为 XSS 攻击敞开大门。