Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to catch HttpRequestValidationException

How can i redirect the user to a custom error page, when HttpRequestValidationException occurred. I tried to catch it in my basecontroller :

protected override void OnException(ExceptionContext exceptionContext)
    {
      if (exceptionContext.Exception is HttpRequestValidationException)
        {
          this.View("CustomError").ExecuteResult(this.ControllerContext);
        }
    }

But i still get the exception : A potentially dangerous request.form value was detected from the client

like image 408
Djave Avatar asked Apr 09 '13 08:04

Djave


1 Answers

This exception occurs much earlier in the execution of the request and cannot be handled by the OnExceptionmethod in a base controller. You could write a global exception handler as I showed in this post.

like image 101
Darin Dimitrov Avatar answered Oct 29 '22 16:10

Darin Dimitrov