HttpRequestValidationException Class
Assembly: System.Web (in system.web.dll)
[SerializableAttribute] public ref class HttpRequestValidationException sealed : public HttpException
/** @attribute SerializableAttribute() */ public final class HttpRequestValidationException extends HttpException
SerializableAttribute public final class HttpRequestValidationException extends HttpException
Not applicable.
Constraining and validating user input is essential in a Web application to prevent hacker attacks that rely on malicious input strings. Cross-site scripting attacks are one example of such hacks. Other types of malicious or undesired data can be passed in a request through various forms of input. By limiting the kinds of data that is passed at a low level in an application, you can prevent undesirable events, even when programmers who are using your code do not put the proper validation techniques in place.
Request validation detects potentially malicious client input and throws this exception to abort processing of the request. A request abort can indicate an attempt to compromise the security of your application, such as a cross-site scripting attack. It is strongly recommended that your application explicitly check all input regarding request aborts. However, you can disable request validation by setting the validateRequest attribute in the @ Page directive to false, as shown in the following example:
<%@ Page validateRequest="false" %>
To disable request validation for your application, you must modify or create a Web.config file for your application and set the validateRequest attribute of the pages section to false, as shown in the following example:
<configuration>
<system.web>
<pages validateRequest="false" />
</system.web>
</configuration>
To disable request validation for all applications on your server, you can make this modification to the Machine.config file.
Note: |
|---|
| It is strongly recommended that your application explicitly check all inputs it uses in addition to the request validation performed by ASP.NET. The request validation feature cannot catch all attacks, especially those crafted specifically against your application logic. |
The following code example demonstrates how to check for malicious user input by using an HttpRequestValidationException.
Security Note: |
|---|
| This example has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview (Visual Studio). |
- AspNetHostingPermission for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
System.Exception
System.SystemException
System.Runtime.InteropServices.ExternalException
System.Web.HttpException
System.Web.HttpRequestValidationException
Note: