I’m currently working on an asp.net mvc 4.0 application and I have a couple of <form> tags here and there … of course, when I intentionally enter HTML tags in the textboxes, I get the following HttpRequestValidationException exception with the following message:
A potentially dangerous Request.Form value was detected from the client…
My goal is NOT to allow malicious script, tags or whatever to be entered (so , I will NOT be using the [AllowHtml] attribute on my properties.).
Instead, what I would like to do is to redirect the user to a specific page telling them that “we’ve detected malicious script(s) …blah blah blah”.
Because of the exception, my Controller’s ActionResult is not being invoked, this means I have to handle this inside the Application_Error() method of the Global.asax.
My question is the following:
How do I redirect the user to a particular Controller (and ActionResult) when I get an HttpRequestValidationException ?
So far, I have the following:
HttpException httpException = exception as HttpException;
if (httpException is HttpRequestValidationException)
{
//FIXME...Redirect to the ErrorController-->InvalidInput() ActionResult
}
How do I acheive the redirect?
Thanks
Try this