ASP.. NET MVC 4和所见即所得编辑器验证

本文关键字:所见即所得 编辑器 验证 NET MVC ASP | 更新日期: 2023-09-27 18:02:14

我正在创建一个ASP。NET MVC 4应用程序,它在表单中包含一个<textarea>。这个<textarea>已经被TinyMCE 4取代。它在客户端运行良好。

然而,由于这是一个所见即所得的编辑器,它显然生成HTML。当表单提交到服务器时,我从ASP得到这个错误。净:

A potentially dangerous Request.Form value was detected from the client 
(Description="<p>Test</p>").
Description: ASP.NET has detected data in the request that is potentially
dangerous because it might include HTML markup or script. The data might
represent an attempt to compromise the security of your application, such 
as a cross-site scripting attack. If this type of input is appropriate in your
application, you can include code in a web page to explicitly allow it.
Exception Details: System.Web.HttpRequestValidationException: A potentially
dangerous Request.Form value was detected from the client
(Description="<p>Test</p>").
Source Error: 
An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can be
identified using the exception stack trace below.

我想关闭这个特定元素的HTML验证,而不是其他地方。我不知道该怎么做。

谁能给我指指方向?

感谢您的宝贵时间。

ASP.. NET MVC 4和所见即所得编辑器验证

使用AllowHtml属性禁用请求验证仅针对特定属性:

[AllowHtml]
public string YourProperty { get; set; }

您可以在这里找到详细的解释:Request Validation in ASP.NET

在服务器端使用HTML Raw方法。链接:http://www.csharpcity.com/2011/outputting-raw-html-in-razor/

Html.Raw(yourHtmlString);