带有 Ckeditor 的 MVC2 应用程序“潜在危险的 Request.Form”

发布于 2024-09-14 01:44:35 字数 1701 浏览 3 评论 0原文

当我使用 FCK 编辑器时,我收到“从客户端检测到潜在危险的 Request.Form 请求值”异常。

如何在提交表单之前进行编码,或者在不禁用数据注释验证的情况下禁用此验证?

这是我的观点的代码:

 <% using (Html.BeginForm()) {%>
        <%: Html.ValidationSummary("Please complete in a right way the fields below.") %>

        <fieldset>
            <legend>Fields</legend>
            <div class="editor-field">
                <%: Html.LabelFor(e => e.Name)%>
                <%: Html.TextBoxFor(e => e.Name)%>
                <%: Html.ValidationMessageFor(e => e.Name)%>
            </div>
            <div class="editor-field">
                <%: Html.LabelFor(e => e.Teaser) %>
                <%: Html.TextAreaFor(e => e.Teaser)%>
                <%: Html.ValidationMessageFor(e => e.Teaser)%>
            </div>
            <div class="editor-field">
                <%: Html.LabelFor(e => e.Description) %>
                <%: Html.TextAreaFor(e => e.Description)%>
                <%: Html.ValidationMessageFor(e => e.Description)%>
            </div>
            <p>
                <input type="submit" />
            </p>
        </fieldset>

    <% } %>

<script type="text/javascript">
   //<![CDATA[
   // This call can be placed at any point after the
   // <textarea>, or inside a <head><script> in a
   // window.onload event handler.
   // Replace the <textarea id="xxxxxx"> with an CKEditor
   // instance, using default configurations.
   CKEDITOR.replace("Description");
   //]]>
</script>

提前非常感谢。

I'm getting the "Potentially dangerous Request.Form request value was detected from the client" exception when im using my FCK editor.

How could encode before submit the form, or disable this validation without disable the Data Anotations validation?

This is the code of my view:

 <% using (Html.BeginForm()) {%>
        <%: Html.ValidationSummary("Please complete in a right way the fields below.") %>

        <fieldset>
            <legend>Fields</legend>
            <div class="editor-field">
                <%: Html.LabelFor(e => e.Name)%>
                <%: Html.TextBoxFor(e => e.Name)%>
                <%: Html.ValidationMessageFor(e => e.Name)%>
            </div>
            <div class="editor-field">
                <%: Html.LabelFor(e => e.Teaser) %>
                <%: Html.TextAreaFor(e => e.Teaser)%>
                <%: Html.ValidationMessageFor(e => e.Teaser)%>
            </div>
            <div class="editor-field">
                <%: Html.LabelFor(e => e.Description) %>
                <%: Html.TextAreaFor(e => e.Description)%>
                <%: Html.ValidationMessageFor(e => e.Description)%>
            </div>
            <p>
                <input type="submit" />
            </p>
        </fieldset>

    <% } %>

<script type="text/javascript">
   //<![CDATA[
   // This call can be placed at any point after the
   // <textarea>, or inside a <head><script> in a
   // window.onload event handler.
   // Replace the <textarea id="xxxxxx"> with an CKEditor
   // instance, using default configurations.
   CKEDITOR.replace("Description");
   //]]>
</script>

Thanks a lot in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

︶ ̄淡然 2024-09-21 01:44:36

[脚本类型=“text/javascript”src=“/ckeditor/_source/core/editor.js”][/script]

CKEDITOR.config.htmlEncodeOutput = true;

[script type="text/javascript" src="/ckeditor/_source/core/editor.js"][/script]

CKEDITOR.config.htmlEncodeOutput = true;

盛夏已如深秋| 2024-09-21 01:44:36

如果您使用 FCK 编辑器或 CKeditor,则不需要处理“requestValidationMode”。因为它将应用于整个应用程序。
您可以执行以下操作:

CKEDITOR.replace('Description', { toolbar: '1', htmlEncodeOutput: true});

然后在控制器中:

model.Body = System.Net.WebUtility.HtmlDecode(model.Body);

If you are working with the FCK editor or CKeditor you do not need to deal with the "requestValidationMode". As it will be applied on the entire application.
You can just do the followings:

CKEDITOR.replace('Description', { toolbar: '1', htmlEncodeOutput: true});

Then in the controller:

model.Body = System.Net.WebUtility.HtmlDecode(model.Body);
灼疼热情 2024-09-21 01:44:35

<httpRuntime requestValidationMode="2.0" />

Check: Request Validation - ASP.NET MVC 2

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文