A Potentially Dangerous Request.form Value Was Detected From The Client

In this article you will come know about how to remove this error while submitting a form to the server.

This error can occur in any page, but mostly a client receives this error while entering a new or modified item / product in admin panel of any portal because in admin panel  we mostly write html code to fill in blanks, and also to display the product feature in ordered or unordered list.

Link for reference about error,

https://stackoverflow.com/questions/81991/a-potentially-dangerous-request-form-value-was-detected-from-the-client

First look at error screen-shot,

Server

Error Description

ASP.NET has detected data in the request that is potentially dangerous because it might include HTML markup or script.

This error description means some one entered HTML markup or script which can be dangerous to the server.

I tried the following things in Text Box with Multiline and was getting this error,

Case 1

Output
In above case1 image you see I had not entered any standard HTML tag but while submitting this form to the server , and this will throw an error.

Case 2

Output

In the above case2 image you see I had entered UL/LI standard HTML tag but while submitting this form to the server this will throw an error.

Solution

Output

You see the above screenshot Project created in .Net Framework 4.5.2 version.

There are two solutions,

Solution1

Just write validateRequest = false in <%@ Page %> @Page directive which is the first line of aspx page.

After writing the above setting in @Page directive save page and reload the page again on browser and submit your data and you won't get error.

Code

ValidateRequest="false"

Output

NOTE

This solution is ok if we want to restrict error for one page but what about the rest of the web pages?

For entire project solution of this error you have to read solution2

Solution2

Just add the following lines in <system.web> section of web.config file afterwards our project will become error free from this error.

Code

<pages validateRequest="false"></pages>

Happy coding….

Up Next
    Ebook Download
    View all
    Learn
    View all