July 20, 2012

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

When we are trying to save HTML content from textbox or any editor to database. we might come across an issue "potentially dangerous Request.Form value was detected"

In case of Framework 2.0 Add ValidateRequest="false" in particular page like this
<%@ Page Language="C#" MasterPageFile="admin.master" AutoEventWireup="true" CodeFile="Test.aspx.cs" ValidateRequest="false" Inherits="Test" %>

OR
 if we need to declare globally add this in web.config
<pages validateRequest="false" /> under <system.web> section
This should work in .Net 2.0

In case of Framework 4.0
Above said alone will not work. Additionally add following in the web.config
<httpRuntime requestValidationMode="2.0"/>

After adding these things, it should go smooth.