我想将 CKEditor 集成到我的 MVC Core 2.0 应用程序中,在之前的版本中,我通过向字符串属性添加 [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://learn.microsoft.com/en-us/aspnet/core/security/cross-site-scripting https://learn.microsoft.com/en-us/aspnet/core/security/cross-site-scripting
[DataType(DataType.MultilineText)]
public string Profile { get; set; }
我真的被这个问题困扰,需要 .Net 专家的帮助,谢谢。
使用 Asp.Net Core razor,您可以通过以下方式将原始 html 输出到页面中:
@Html.Raw(theString)
我觉得有义务指出你需要确保theString
包含安全的 HTML 输出,这样就不会为 XSS 攻击敞开大门。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)