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

标签 c# asp.net asp.net-mvc validation tinymce

我正在创建一个 ASP.NET MVC 4 应用程序,其中包含 <textarea>在一个表格里面。这<textarea>已替换为 TinyMCE 4.x它在客户端运行良好。

但是,由于这是一个所见即所得的编辑器,它显然生成了 HTML。将表单提交到服务器时,我从 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.

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

有人可以指导我吗?

感谢您的宝贵时间。

最佳答案

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

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

您可以在此处找到详细说明:Request Validation in ASP.NET

关于c# - ASP.NET MVC 4 和 WYSIWYG 编辑器验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23504594/

相关文章:

c# - 有什么方法可以从R中调用.NET的字符串库吗?

c# - 主页错误,命名空间已存在

c# - 如何为我的 asp.net MVC 站点的每个访问者添加 cookie?

c# - 如何将日期从一种文化转换为另一种文化?

asp.net - 我如何验证日期?

asp.net-mvc - ASP.Net MVC 强类型部分 View 和继承属性

c# - 如何将我的 .net WinForms 应用程序转换为 Windows 10 Mobile?

C# 打开文件的问题

c# - 字段列表中的未知列 - MySQL 更改后

c# - 隐藏网格中的列