Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to handle request validation exception

How to handle request validation exception

Scheduled Pinned Locked Moved ASP.NET
csharphtmlasp-netsysadmindata-structures
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    THE SK
    wrote on last edited by
    #1

    Hi All I have the following code <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <script language="C#" runat="server"> protected void button1_Click(object sender, EventArgs e) { try { TextBox1.Text = (TextBox1.Text + "<strong></strong>"); Label1.Text = (TextBox1.Text); } catch (System.Web.HttpRequestValidationException) { Response.Write("html is not allowed"); } } </script> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Height="300px" Width="400px"></asp:TextBox> </div> <asp:Button ID="button1" runat="server" Text="strong" onclick="button1_Click" /> <asp:Label ID="Label1" runat="server"></asp:Label> </form> </body> </html> If i click on button twice I am getting request validation exception which I want to catch. The error which I am getting is ************************************************************************* Server Error in '/TextControlOnSite' Application. -------------------------------------------------------------------------------- A potentially dangerous Request.Form value was detected from the client (TextBox1="<strong></strong>"). Description: Request Validation has detected a potentially dangerous client input value, and processing of the request has been aborted. This value may indicate an attempt to compromise the security of your application, such as a cross-site scripting attack. You can disable request validation by setting validateRequest=false in the Page directive or in the configuration section. However, it is strongly recommended that your application explicitly check all inputs in this case. Exception Details: System.Web.HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client (TextBox1="<strong></strong>"). Source Error: [No relevant source lines] Source File: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\textcontrolonsite\d5a3eadf\30926e30\App_Web_rwvmmuiv.0.cs Line: 0 Stack Trace: [HttpRequestValidationException (0x80004005): A poten

    A B 2 Replies Last reply
    0
    • T THE SK

      Hi All I have the following code <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <script language="C#" runat="server"> protected void button1_Click(object sender, EventArgs e) { try { TextBox1.Text = (TextBox1.Text + "<strong></strong>"); Label1.Text = (TextBox1.Text); } catch (System.Web.HttpRequestValidationException) { Response.Write("html is not allowed"); } } </script> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Height="300px" Width="400px"></asp:TextBox> </div> <asp:Button ID="button1" runat="server" Text="strong" onclick="button1_Click" /> <asp:Label ID="Label1" runat="server"></asp:Label> </form> </body> </html> If i click on button twice I am getting request validation exception which I want to catch. The error which I am getting is ************************************************************************* Server Error in '/TextControlOnSite' Application. -------------------------------------------------------------------------------- A potentially dangerous Request.Form value was detected from the client (TextBox1="<strong></strong>"). Description: Request Validation has detected a potentially dangerous client input value, and processing of the request has been aborted. This value may indicate an attempt to compromise the security of your application, such as a cross-site scripting attack. You can disable request validation by setting validateRequest=false in the Page directive or in the configuration section. However, it is strongly recommended that your application explicitly check all inputs in this case. Exception Details: System.Web.HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client (TextBox1="<strong></strong>"). Source Error: [No relevant source lines] Source File: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\textcontrolonsite\d5a3eadf\30926e30\App_Web_rwvmmuiv.0.cs Line: 0 Stack Trace: [HttpRequestValidationException (0x80004005): A poten

      A Offline
      A Offline
      Anurag Gandhi
      wrote on last edited by
      #2

      The solution is present in your exception itself. put validateRequest="false" in your <%@ Page directive This will solve your problem. Try google and you will know why this exception occurs while posting back.

      Anurag Gandhi. http://www.gandhisoft.com Life is a computer program and every one is the programmer of his own life.

      1 Reply Last reply
      0
      • T THE SK

        Hi All I have the following code <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <script language="C#" runat="server"> protected void button1_Click(object sender, EventArgs e) { try { TextBox1.Text = (TextBox1.Text + "<strong></strong>"); Label1.Text = (TextBox1.Text); } catch (System.Web.HttpRequestValidationException) { Response.Write("html is not allowed"); } } </script> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Height="300px" Width="400px"></asp:TextBox> </div> <asp:Button ID="button1" runat="server" Text="strong" onclick="button1_Click" /> <asp:Label ID="Label1" runat="server"></asp:Label> </form> </body> </html> If i click on button twice I am getting request validation exception which I want to catch. The error which I am getting is ************************************************************************* Server Error in '/TextControlOnSite' Application. -------------------------------------------------------------------------------- A potentially dangerous Request.Form value was detected from the client (TextBox1="<strong></strong>"). Description: Request Validation has detected a potentially dangerous client input value, and processing of the request has been aborted. This value may indicate an attempt to compromise the security of your application, such as a cross-site scripting attack. You can disable request validation by setting validateRequest=false in the Page directive or in the configuration section. However, it is strongly recommended that your application explicitly check all inputs in this case. Exception Details: System.Web.HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client (TextBox1="<strong></strong>"). Source Error: [No relevant source lines] Source File: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\textcontrolonsite\d5a3eadf\30926e30\App_Web_rwvmmuiv.0.cs Line: 0 Stack Trace: [HttpRequestValidationException (0x80004005): A poten

        B Offline
        B Offline
        Brij
        wrote on last edited by
        #3

        Why do you want to catch exception at server side.. you can do it by custom validator also but if you want to do it server side only... put ValidateRequest="false" in page attribute.. Now .Net allow this request to go server side.Now make your handler to throw some exception according to your need and show the message accordingly..

        Cheers!! Brij

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups