catch HttpRequestValidationException

  1. #1

    catch HttpRequestValidationException

    hi there, i'm trying to catch the HttpRequestValidationException through the global.ascx but can't somehow get the error using the ajaxevent failure property


    
            Exception ex = Server.GetLastError();
            if (ex is HttpRequestValidationException)
            {
               
                    Response.Clear();
                    Response.StatusCode = 200;
                    string response = "<html><head><title>HTML Not Allowed</title>";
                    response += "</head>";
                    response += "<body style=\"font-family: Arial, Sans-serif;\">";
                    response += "<p>I'm sorry, but HTML entry is not allowed on that page.</p>";
                    response += "<p>Please make sure that your entries do not contain ";
                    response += "any angle brackets like &amp;lt; or &amp;gt;.</p>";
                    response += "<p><a href=\"history.go(-1);\">Go back</a></p>";
                    response += "</body></html>";
                    Response.Write(response);
                    Response.End();
            }
  2. #2

    RE: catch HttpRequestValidationException

    Hi,

    I am not sure that clear understood you. Please provide more details with test sample
  3. #3

    RE: catch HttpRequestValidationException

    i added the following code to the global asax to catch the error generated on putting html tags in textboxes while validateRequest = true

    
    void Application_Error(object sender, EventArgs e) 
        { 
            //Code that runs when an unhandled error occurs
            Exception ex = Server.GetLastError();
            if (ex is HttpRequestValidationException)
            {
    
                Response.Clear();
                Response.StatusCode = 400;
                string response = "";
                if (Coolite.Ext.Web.Ext.IsAjaxRequest)
                {
                    Response.ClearContent();
                    Response.StatusCode = 555;
                    Response.StatusDescription = "Internal Error";
                    response = "HTML entry is not allowed on this page";
                }
                else
                {
                    response = "<html><head><title>HTML Not Allowed</title>";
                    response += "</head>";
                    response += "<body style=\"font-family: Arial, Sans-serif;\">";
                    response += "<p>I'm sorry, but HTML entry is not allowed on that page.</p>";
                    response += "<p>Please make sure that your entries do not contain ";
                    response += "any angle brackets like &amp;lt; or &amp;gt;.</p>";
                    response += "<p><a href=\"history.go(-1);\">Go back</a></p>";
                    response += "</body></html>";
                }
                Response.Write(response);
                Response.End();
            }
        }
    but i cannot get it on the ajaxevent's failuire property ( result.errorMessage property )
  4. #4

    RE: catch HttpRequestValidationException

    it seems that the response is going to the response.resultText property? how can i set the result.errorMessage property instead?
  5. #5

    RE: catch HttpRequestValidationException

    Hi,

    No way. As you can see the ASP.NET build own response for that unhandled exception

Similar Threads

  1. [CLOSED] Catch 404 Error
    By speedstepmem4 in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Feb 13, 2012, 9:06 AM
  2. Catch the OnUnload Ajaxevent
    By javito in forum 1.x Help
    Replies: 1
    Last Post: Jun 30, 2010, 4:35 AM
  3. Catch Exceptions
    By Dominik in forum 1.x Help
    Replies: 1
    Last Post: Jun 10, 2010, 7:39 AM
  4. [CLOSED] Event Catch-Up bug w/BorderLayout
    By randy85253 in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Oct 04, 2009, 2:39 PM
  5. [CLOSED] Catch any failure
    By acrossdev in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jul 23, 2009, 7:27 AM

Posting Permissions