简体   繁体   English

ASP.NET MVC 4和WYSIWYG编辑器验证

[英]ASP.NET MVC 4 and WYSIWYG Editor Validation

I am creating an ASP.NET MVC 4 application which includes a <textarea> inside of a form. 我正在创建一个ASP.NET MVC 4应用程序,其中包含表单内的<textarea> This <textarea> has been replaced with TinyMCE 4.x and it functions well on the client-side. 这个<textarea>已被TinyMCE 4.x取代,它在客户端运行良好。

However, since this is a WYSIWYG editor, it obviously generated HTML. 但是,由于这是一个WYSIWYG编辑器,它显然生成了HTML。 When the form is submitted to the server, I get this error from ASP.NET: 当表单提交到服务器时,我从ASP.NET收到此错误:

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.

I would like to turn off HTML validation for this particular element, and no where else. 我想关闭这个特定元素的HTML验证,而不是其他地方。 I am not sure how I can do this. 我不知道怎么能这样做。

Could someone please direct me? 有人可以指导我吗?

Thank you for your time. 感谢您的时间。

Use AllowHtml attribute to disable request validation for only specific property: 使用AllowHtml属性仅禁用特定属性的请求验证

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

You can find detailed explanation here: Request Validation in ASP.NET 您可以在此处找到详细说明: Request Validation in ASP.NET

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

Html.Raw(yourHtmlString);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM