Monday, July 14, 2008

ValidateRequest in Page directive in asp.net

ASP.NET 2.0 validates form input values for potentially dangerous entries such as the '<' and '>' characters. When I enter the value '<' and '>' in textbox in .Net web form, it returns an error like 'Sys.WebForms.PageRequestManagerServerErrorException: An unkown erroroccured while processing the request on the server. The status code returned from the server was: 500'. So I search on google indicates the below solution for this :
  • Add ValidateRequest = "false" in the Page directive.
    <%@ Page Language="vb" AutoEventWireup="false" Codebehind="sample.aspx.cs"
    Inherits="KannanDemo.sample" validateRequest="false"%>
    After added it and run the application. This time I got the error like The 'ValidateRequest' attribute is not supported by the 'Page directive.'

  • Then I found another way to solve this issue by adding <pages ValidateRequest="false"/> in System.Web of the Web.Config file. I got the result.

Note:

The main disadvantage of setting the ValidateRequest to false on a page is the openning of an opportunity to hack your page, because the ValidateRequest's job is to ensure that the most common injection attacks are not possible for your page, and so if you disable it then you should start making all the necessary changes to avoid SQL Injection, Script Injection, and so on.

Happy coding!!!