What is the alternate of [AllowHtml] in ASP.Net Core 2.0 [duplicate]

依然范特西╮ 提交于 2020-02-24 08:59:35

问题


I want to integrate CKEditor in my MVC Core 2.0 Application, in previous version I used it by adding [AllowHTML] data annotation to my string property. But in ASP.Net Core I could not find the right way to insert HTML into string input.

My code in in ASP.Net MVC 5

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

but in ASP.Net Core 2.0 [AllowHtml] is not working. I searched in google but could not find right solution except this link https://docs.microsoft.com/en-us/aspnet/core/security/cross-site-scripting

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

I am really stuck with this issue and need help from .Net experts, Thanks.


回答1:


Using Asp.Net Core razor you can output raw html into the page via the following:

     @Html.Raw(theString)

I feel obligated to point out that you need to ensure that theString contains safe HTML to output such that it isn't an open door for XSS attacks.



来源:https://stackoverflow.com/questions/48514226/what-is-the-alternate-of-allowhtml-in-asp-net-core-2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!