I have a Web API 2 project with several routes and controllers. I began testing some fairly standard security functionality including SQL Injection. I attempted to pass a request parameter of "*" to a route with database operations. Immediately I was met with a detailed response in the form of HTML which was less than useful for my C# console application I was using to test.
The HTML did have the only real piece of information I wanted however, which was the exception message, along with the status code. Here is part of the HTML:
<body bgcolor="white">
<span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1>
<h2> <i>A potentially dangerous Request.Path value was detected from the client (*).</i> </h2></span>
<font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">
<b> Description: </b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
...
This security exception is thrown before it enters one of my custom controllers where I have error-handling logic in place. Is there a way to override this HTML that is returned, and instead return a standard HttpResponse or HttpResponseMessage without completely replacing the standard security measures that are clearly functioning properly here before it even gets to my routes? Is this an unwise idea? Is this a configurable setting?