【问题标题】:Fix A potentially dangerous error with using text editor form修复使用文本编辑器表单的潜在危险错误
【发布时间】:2020-01-20 23:09:49
【问题描述】:

我正在为我的表单使用 ck 编辑器

ck编辑器发送<p>标签,我收到

A potentially dangerous Request.Form value was detected from the client (title=<p>efrgth</p> error 

表格中的代码:

<div class="form-group">
    @Html.LabelFor(model => model.title, htmlAttributes: new { @class = "control-label col-md-2" })
    <div class="col-md-10">
        <textarea id="content" name="title" class="ckeditor form-control" dir="rtl"></textarea>
        @Html.ValidationMessageFor(model => model.title, "", new { @class = "text-danger" })
    </div>
</div>

【问题讨论】:

  • 另外,请花一些时间查看stackoverflow.com/editing-help#code - 代码围栏是使用反引号,`,而不是撇号。
  • @TiesonT.hi 我读了这个问题,但我不使用允许 html 我想修复 ck 编辑器
  • CKEditor 没有问题,你不需要“修复”它。它是一个 HTML 编辑器。因此,如果您想正确使用它,您需要进行一些更改,以便您的服务器能够接受来自它的传入 HTML。因此,建议在该链接的一些较新答案中使用 [AllowHtml] 属性。

标签: html asp.net asp.net-mvc


【解决方案1】:

将以下代码添加到您的页面标签 (WebForms):

validateRequest="false"

例如:

<%@ Page Language="C#" AutoEventWireup="true" ValidateRequest="false"
EnableEventValidation="true" CodeBehind="Test.aspx.cs" Inherits="Test" %>

如果是 MVC,请使用以下代码:

[ValidateInput(false)]
public class YourController : Controller
{

}

【讨论】:

  • 请让这个例子更适合MVC,而不是WebForms
猜你喜欢
  • 2016-03-13
  • 2017-07-04
  • 2011-03-07
  • 1970-01-01
  • 2012-11-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-09
相关资源
最近更新 更多