A Potentially Dangerous Request Form Value was Detected from the Client in ASP.NET

Solution

A potentially dangerous request form value was detected from the client in ASP.Net

When posting HTML characters to an ASP.Net page, we normally get this error as – “A potentially dangerous Request.Form value was detected from the client in asp.net“. This post explains how to resolve this problem. To resolve this problem on a single page, you can set the “validateRequest” property of a page to false as shown below.

< %@ Page Title="PotentialDangerous Page" ValidateRequest="false" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="PotentialDangerous.aspx.cs" Inherits="TestProject.PotentialDangerous"%>

In case you want to set it for the entire application, you can set the property for all pages under System.Web section in web.config file of the application as below.

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

The above mentioned solution works for solutions that are not targeting .Net 4.0 and higher. If you are using .Net 4.0 or higher, you need to add another setting in your web.config file as below.

<httpruntime requestValidationMode = "2.0"></httpruntime>

Hope this helps! Keep learning and sharing! Cheers! 

Ebook Download
View all
Learn
View all
Think. Innovate. Grow.