Search Your Dot Net Topic

Monday, 8 January 2018

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 form to the server.


This error can be occurred in any page but mostly client receive this error while entering new or modify item / product in admin panel of any portal because in admin panel fill blanks mostly we write html code also to display the product feature in order list or unorder list.

Link for reference about error:


First look on error screen-shot :


Asp-Net-MVC-Training-Institute-Goregoan-East , Asp-Net-MVC-Training-Institute-Malad-East
Asp-Net-MVC-Training-Institute-Goregoan-East , Asp-Net-MVC-Training-Institute-Malad-East












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 had tried following things in Text Box with Multiline for getting this error:

Case 1:

Asp-Net-MVC-Training-Institute-Kandivali-East , Asp-Net-MVC-Training-Institute-Malad-East
Asp-Net-MVC-Training-Institute-Kandivali-East , Asp-Net-MVC-Training-Institute-Malad-East


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


Solution:

Asp-Net-MVC-Training-Institute-Kandivali-East , Asp-Net-MVC-Training-Institute-Borivali-East
Asp-Net-MVC-Training-Institute-Kandivali-East , Asp-Net-MVC-Training-Institute-Borivali-East
You see above screenshot Project created in .Net Framework 4.5.2 version.

There is two solutions:

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

After write above setting in @Page directive save page and reload the page again on browser and submit your data you wont be get error.

Code:
ValidateRequest="false"

Asp-Net-MVC-Training-Institute-Borivali-East , Asp-Net-MVC-Training-Institute-Dahisar-East
Asp-Net-MVC-Training-Institute-Borivali-East , Asp-Net-MVC-Training-Institute-Dahisar-East






NOTE: This solution is ok if We want to restrict error for one page but what about of rest of web pages.  For entire project solution of this error you have to read solution2




Solution2:
Just add 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….

No comments:

Post a Comment