Click here to Skip to main content
Click here to Skip to main content

ASP.NET 4.0 potentially dangerous Request.Form value was detected

By , 6 Feb 2013
 

A few days ago, while working on an ASP.NET 4.0 Web project, I got an issue. The issue was, when user enters non-encoded HTML content into a comment text box s/he got something like the following error message:

"A potentially dangerous Request.Form value was detected from the client".

This was because .NET detected something in the entered text which looked like an HTML statement. Then I got a link Request Validation, that is a feature put in place to protect your application cross site scripting attack and followed accordingly.

To disable request validation, I added the following to the existing "page" directive in that .aspx file.

ValidateRequest="false"

But I still got the same error. Later I found that, for .NET 4, we need to add requestValidationMode="2.0" to the httpRuntime configuration section of the web.config file like the following:

<httpRuntime requestValidationMode="2.0"/>

But if there is no httpRuntime section in the web.config file, then this goes inside the <system.web> section.

If anyone wants to turn off request validation globally for a user, the following line in the web.config file within <system.web> section will help:

<pages validateRequest="false" />  

Note: But always avoid the last example because there is a huge security issue. The request validation feature in ASP.NET provides a certain level of default protection against cross-site scripting (XSS) attacks.

However, we recommend that you analyze any request validation errors to determine whether existing handlers, modules, or other custom code accesses potentially unsafe HTTP inputs that could be XSS attack vectors.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Monjurul Habib
Software Developer (Senior)
Bangladesh Bangladesh
Software Engineer with years of successful records serving mid and large scale .NET applications. Have a wide range of experience working in domestic and international client environment. Expertise in different areas of software development life cycles and Software Architecture. I always love to learn new technologies and share with others.
 
Father of a wonderful, smart kid and passionately in love with my wife and life-partner Smile | :)
Follow on   Twitter

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 5memberAjith_joseph3-Aug-12 0:46 
GeneralRe: My vote of 5memberMonjurul Habib3-Aug-12 2:31 
GeneraltanxmemberBehzad Habibzadeh11-Jul-12 1:21 
GeneralRe: tanxmemberMonjurul Habib3-Aug-12 2:31 
QuestionhimemberNitin Kumar Chaudhary27-Jun-12 22:55 
AnswerRe: himemberMonjurul Habib28-Jun-12 20:13 
GeneralMy vote of 5memberwalkerwzy22-Jun-12 21:16 
GeneralRe: My vote of 5memberMonjurul Habib24-Jun-12 21:37 
GeneralRealy HelpfullmemberArman Erfani11-Jun-12 21:34 
GeneralRe: Realy HelpfullmemberMonjurul Habib14-Jun-12 10:05 
GeneralMy vote of 5membertechchallenger6-May-12 14:23 
GeneralRe: My vote of 5memberMonjurul Habib7-May-12 21:17 
GeneralReason for my vote of 5 Exactly my scenario, and was helpfulmemberMember 467175418-Feb-12 9:33 
GeneralRe: thank youmemberMonjurul Habib25-Feb-12 23:52 
GeneralReason for my vote of 5 excellent postmemberjpmontoya18226-Dec-11 7:43 
GeneralRe: thank youmemberMonjurul Habib26-Dec-11 8:25 
GeneralReason for my vote of 5 Run into this several times recently...memberPeterA20-Dec-11 10:14 
GeneralRe: thank youmemberMonjurul Habib20-Dec-11 19:28 
GeneralThis does not address the security aspect of setting Validat...memberdavecal20-Dec-11 3:47 
GeneralRe: This is merely another example of microsoft trying to 'save'...memberVerrice22-Dec-11 6:10 
GeneralReason for my vote of 3 While this is a workaround it doesn'...memberdavecal20-Dec-11 3:45 
GeneralThis will be easier with ASP.NET 4.5: http://www.asp.net/vne...memberRichard Deeming15-Dec-11 8:41 
GeneralRe: I was talking about ASP.NET 4.0, anyway thank youmemberMonjurul Habib18-Dec-11 16:48 
GeneralReason for my vote of 5 Excellent. Needs a link or an extent...memberDave Vroman14-Dec-11 5:23 
GeneralRe: thank youmemberMonjurul Habib14-Dec-11 6:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130617.1 | Last Updated 6 Feb 2013
Article Copyright 2011 by Monjurul Habib
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid