Click here to Skip to main content
12,071,437 members (65,902 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


26 bookmarked

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)
Bangladesh Bangladesh
A life-long-learner, maker and soft music fan. Likes building things to solve problems. Lives in Dhaka with wife and wonderful, smart kid and works as a Senior Software Engineer in applications architecture team.

Has 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 information and value feedback (especially where got something wrong!).

You may also be interested in...

Comments and Discussions

QuestionA potentially dangerous Request.Form value was detected from the client in Pin
monika salunkhe13-Jan-16 3:49
membermonika salunkhe13-Jan-16 3:49 
QuestionQuestions Pin
Member 88831-Jan-15 3:19
memberMember 88831-Jan-15 3:19 
GeneralMy vote of 5 Pin
Humayun Kabir Mamun14-Jan-15 3:59
memberHumayun Kabir Mamun14-Jan-15 3:59 
Questionquestion Pin
Ehsan yazdani rad14-Jul-14 3:57
memberEhsan yazdani rad14-Jul-14 3:57 
GeneralMy vote of 5 Pin
Pratik Bhuva6-Mar-14 23:50
professionalPratik Bhuva6-Mar-14 23:50 
GeneralSolution to error Potentially dangerous request form value was detected from the client Pin
samunder20-Feb-14 19:15
membersamunder20-Feb-14 19:15 
Questionthanks dear Pin
rajveersingh24-Jan-14 1:31
memberrajveersingh24-Jan-14 1:31 
QuestionThanks... Pin
Member 995208821-Oct-13 21:04
memberMember 995208821-Oct-13 21:04 
Questionthanks great Pin
Himanshu Kamothi24-Jul-13 4:54
memberHimanshu Kamothi24-Jul-13 4:54 
AnswerRe: thanks great Pin
Monjurul Habib24-Jul-13 9:29
professionalMonjurul Habib24-Jul-13 9:29 

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.

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