Handle "potentially dangerous Request.Form value..." Handle "potentially dangerous Request.Form value..." asp.net asp.net

Handle "potentially dangerous Request.Form value..."


You have two options:

// Editing your global.asax.cspublic class Global : System.Web.HttpApplication{    protected void Application_Error(object sender, EventArgs e)    {        Exception lastError = Server.GetLastError();        if (lastError is HttpRequestValidationException)        {            Response.Redirect("~/RequestValidationError.aspx");        }    }}

Or

// Editing your CUser.aspx.cspublic partial class CUser : System.Web.UI.Page{    protected override void OnError(EventArgs e)    {        Response.Redirect("~/RequestValidationError.aspx");        Context.ClearError();    }}


You don't want to go adding unnecessary baggage to the Global.asax. If you're satisfied that this is caused by spurious data input, then deal with the input, no matter where it's coming from:

http://codersbarn.com/post/2008/11/01/ASPNET-Data-Input-Validation.aspx

Concentrate on the cause of the error :-)


You can use Server.GetLastError() in Application_Error to get the exception that was thrown, inspect the exception, and respond as you like to it (redirect to a page, etc)