Problem going to the server when loading tinymce component

Asked

Viewed 509 times

1

When I enter information into the tinymce component and click on any button that submits the form has generated the error.

Error in Javascript runtime: Sys.WebForms.Pagerequestmanagerservererrorexception: An error has occurred unknown while processing the request on the server. The code of status returned from server was: 500

It seems to me that Asp.net is blocking the HTML of the component. 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"

           });

inserir a descrição da imagem aqui

1 answer

1


The problem, as you may have determined, is the HTML formatting of tinymce content: ASP.Net understands this content as unsafe and blocks the request.

You may have put the ValidateRequest="false" in the wrong place. It is right to put it in the guideline Page:

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

And on your web.conf you should put

 <httpRuntime requestValidationMode="2.0"/>

The best solution, in my opinion, is to write an Handler for the event onclick button submit and convert the text to HTML Encoded in 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 processing of onclick on the page .aspx which 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 the tip is a version that I have been using in my projects and were originally obtained in this link.

Add requestValidationMode="2.0" specifies that . Net 2 validation style should be used instead of 4, which is the default in case you are using . Net 4.

No. Net 2, validation only occurs for page requests, and not for all other pages like Ajax, and in addition, page validation settings in the settings file or in the guideline Page of your page are taken into account.

The . Net 4, on the other hand, ignores these settings. That is why I prefer not to use these validation settings but to use the method with StringBuilder. However, it did not occur to me that you were using . Net 4 in my initial reply.

  • I am putting Validaterequest="false" in the same Page directive. My problem that the click wind does not call my aspx.Cs

  • Complete your question with more code. As it stands, only this can be inferred.

  • <httpRuntime requestValidationMode="2.0"/> I put this in my code and it worked. Could you explain why? Thank you.

  • I supplemented my answer.

  • Thank you for the reply.

  • do you think it’s best to change the question so it gets more Generic? Type. Server-side validation with HTML text components.

  • I think it doesn’t matter, because both the Google search and the OS search already consider the text of the question.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.