【问题标题】:What is the alternate of [AllowHtml] in ASP.Net Core 2.0 [duplicate]ASP.Net Core 2.0中[AllowHtml]的替代品是什么[重复]
【发布时间】:2018-07-08 21:56:00
【问题描述】:

我想将 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://docs.microsoft.com/en-us/aspnet/core/security/cross-site-scripting

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

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

【问题讨论】:

  • 其实我想在我的应用程序中集成CKEDITOR。和 @Html.TextAreaFor(item => item.Profile, new { @id = "editor1" }) 正确呈现 CKEDITOR 但是当我使用 HTML Tag Helpers 它不呈现 CKEDITOR
  • 那么是什么阻止了你?
  • CKEDITOR 在我使用公共字符串 Profile { get; 时不起作用放; }
  • 什么不起作用?

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


【解决方案1】:

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

     @Html.Raw(theString)

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

【讨论】:

  • 谢谢,我已经这样做了,而且工作正常。那个话题已经解决了。
猜你喜欢
  • 1970-01-01
  • 2018-05-31
  • 2018-04-13
  • 1970-01-01
  • 1970-01-01
  • 2017-12-25
  • 2018-11-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多