Click here to Skip to main content
12,827,276 members (42,340 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


27 bookmarked
Posted 9 Dec 2011

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

, 6 Feb 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
If anyone enters non-encoded HTML content into a text box in an ASP.NET application.

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.


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.


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)
Singapore Singapore
A life-long-learner, maker and soft music fan. Likes building things to solve problems. Years of successful records serving mid and large scale .NET applications in domestic and international client environment. Expertise in different areas of software development life cycles and Software Architecture.

Always looks for new technology and loves to get hands dirty Smile | :)

You may also be interested in...

Comments and Discussions

GeneralMy vote of 5 Pin
dpalash2-May-13 4:14
professionaldpalash2-May-13 4:14 
GeneralRe: My vote of 5 Pin
Monjurul Habib24-Jul-13 9:28
professionalMonjurul Habib24-Jul-13 9:28 
GeneralMy vote of 3 Pin
DrTJ20668-Mar-13 5:23
memberDrTJ20668-Mar-13 5:23 
QuestionBest of both worlds Pin
Isaac Shloss26-Dec-12 11:04
memberIsaac Shloss26-Dec-12 11:04 
AnswerRe: Best of both worlds Pin
minLVwang9-Jan-13 17:28
memberminLVwang9-Jan-13 17:28 
QuestionPartially dangerous solution! Pin
Jurisfox9-Nov-12 2:23
memberJurisfox9-Nov-12 2:23 
AnswerRe: Partially dangerous solution! Pin
Monjurul Habib9-Nov-12 11:06
memberMonjurul Habib9-Nov-12 11:06 
GeneralMy vote of 5 Pin
Member 89619178-Nov-12 4:28
memberMember 89619178-Nov-12 4:28 
GeneralRe: My vote of 5 Pin
Monjurul Habib8-Nov-12 8:54
memberMonjurul Habib8-Nov-12 8:54 
QuestionGreat Solution!!!!! Pin
nickT.Tnick18-Oct-12 23:07
membernickT.Tnick18-Oct-12 23:07 
AnswerRe: Great Solution!!!!! Pin
Monjurul Habib19-Oct-12 7:37
memberMonjurul Habib19-Oct-12 7:37 
GeneralMy vote of 5 Pin
Ajith_joseph3-Aug-12 1:46
memberAjith_joseph3-Aug-12 1:46 
GeneralRe: My vote of 5 Pin
Monjurul Habib3-Aug-12 3:31
memberMonjurul Habib3-Aug-12 3:31 
Generaltanx Pin
Behzad Habibzadeh11-Jul-12 2:21
memberBehzad Habibzadeh11-Jul-12 2:21 
GeneralRe: tanx Pin
Monjurul Habib3-Aug-12 3:31
memberMonjurul Habib3-Aug-12 3:31 
Questionhi Pin
Nitin Kumar Chaudhary27-Jun-12 23:55
memberNitin Kumar Chaudhary27-Jun-12 23:55 
AnswerRe: hi Pin
Monjurul Habib28-Jun-12 21:13
memberMonjurul Habib28-Jun-12 21:13 
GeneralMy vote of 5 Pin
walkerwzy22-Jun-12 22:16
memberwalkerwzy22-Jun-12 22:16 
GeneralRe: My vote of 5 Pin
Monjurul Habib24-Jun-12 22:37
memberMonjurul Habib24-Jun-12 22:37 
GeneralRealy Helpfull Pin
Arman Erfani11-Jun-12 22:34
memberArman Erfani11-Jun-12 22:34 
GeneralRe: Realy Helpfull Pin
Monjurul Habib14-Jun-12 11:05
memberMonjurul Habib14-Jun-12 11:05 
GeneralMy vote of 5 Pin
techchallenger6-May-12 15:23
membertechchallenger6-May-12 15:23 
GeneralRe: My vote of 5 Pin
Monjurul Habib7-May-12 22:17
memberMonjurul Habib7-May-12 22:17 
GeneralReason for my vote of 5 Exactly my scenario, and was helpful Pin
Member 467175418-Feb-12 10:33
memberMember 467175418-Feb-12 10:33 
GeneralRe: thank you Pin
Monjurul Habib26-Feb-12 0:52
memberMonjurul Habib26-Feb-12 0:52 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

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