How to catch an HttpRequestValidationException exception

How can I redirect the user to the user error page when an HttpRequestValidationException occurred. I tried to catch it in my base controller:

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

But I still get an exception: A potentially dangerous request.form value was found at the client

+5
source share
1 answer

This exception occurs much earlier when the request is executed and cannot be handled by the method OnExceptionin the base controller. You can write a global exception handler, as shown in this post.

+5
source

All Articles