Problem to go to server while loading tinyMCE component

1

When I insert information into the tinyMCE component and click on any button that submits the form, it has generated the error.

  

JavaScript run-time error:   Sys.WebForms.PageRequestManagerServerErrorException: An error has occurred   when processing the request on the server. The   status returned from server was: 500

It seems to me that Asp.net is barring the component's HTML. I'm already using the ValidateRequest="false" .

My code

<%@ Page UICulture="auto" ValidateRequest="false"  Culture="auto" Language="C#" MasterPageFile="~/ius/MasterPage.master"
    AutoEventWireup="true" CodeFile="CadastroNormas.aspx.cs" Inherits="CadastroNormas"
    Title="Cadastro de Normas" AsyncTimeout="600" %>

 <asp:UpdatePanel ID="upnlArquivos" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
        <ContentTemplate>
           <span class="txtCampo">Texto da Norma:</span><br />
             <asp:TextBox ID="Spaw2" runat="server" TextMode="MultiLine" Rows="100"
                  Columns="100"></asp:TextBox>
                 <br />
                 <br />
              </ContentTemplate>                           
             </asp:UpdatePanel>

           tinyMCE.init(
           {
               mode: "specific_textareas",
               editor_selector: "mceEditor",
               height: "400",
               theme: "modern",
               entity_encoding: "raw",

               content_css: "../estilo.css",

               //Hacks para manter a formatação vinda do word
               forced_root_block: false,
               paste_auto_cleanup_on_paste: false,
               paste_text_use_dialog: true,
               paste_force_cleanup_paste: false,
               paste_remove_spans: false,
               paste_retain_style_properties: "margin, padding, width, height, font-size, font-weight, font-family, color, text-align, ul, ol, li, text-decoration, border, background, float, display"

           });

    
asked by anonymous 23.10.2014 / 15:31

1 answer

1

The problem, as you may have determined, is the HTML formatting of tinyMCE content: ASP.Net understands this content to be insecure and blocks the request.

You may have put ValidateRequest="false" in the wrong place. The correct thing is to put it in the Page directive:

<%@ Page Language="C#" ValidateRequest="false"%>

And in your web.conf you should put

 <httpRuntime requestValidationMode="2.0"/>

The best solution, in my opinion, is to write a handler for the onclick event of the submit button and convert the text to HTML Encoded to a StringBuilder .

It would be something like this:

<html>  
  <body>  
    <form id="form1" runat="server">  
      <div>  
        <asp:textbox id="htmlInputTxt" runat="server" textmode="MultiLine" width="318px" height="168px">  
        </asp:textbox>  
        <asp:button id="submitBtn" runat="server" text="Submit" onclick="submitBtn_Click">  
        </asp:button>  
      </div>  
    </form>  
  </body>  
</html>

The onclick processing on the .aspx page that processes the request is:

<script runat="server">  
  void submitBtn_Click(object sender, EventArgs e) {  
    StringBuilder sb = new StringBuilder(HttpUtility.HtmlEncode(htmlInputTxt.Text));  
    Response.Write(sb.ToString());  
  }  
</script>

The codes and hint are a version I've been using in my projects and were originally obtained from this link .

Add% with% specifies that the .Net 2 validation style should be used, rather than 4, which is the default in case you are using .Net 4.

In .Net 2, validation only occurs for page requests, not for all other requests such as Ajax, and, in addition, page validation settings in the configuration file or in the requestValidationMode="2.0" your page are taken into account.

Net 4, on the other hand, ignores these settings. So I prefer not to use these validation settings, but to use the Page method. However, it did not occur to me that you were using .Net 4 in my initial response.

    
23.10.2014 / 17:14