I have an asp.net MVC3 application. In my controller I have an ajax action that sets custom response code using Response.StatusCode = 600. I need to pass through the response as is without the IIS trying to look for the custom error page. I tried to use the following code to let IIS not use its custom page for response status of 600.
<!-- Pass through Ajax Errors with status code 600 -->
<httpErrors errorMode="Detailed" existingResponse="PassThrough">
<error statusCode="600" path="/" />
</httpErrors>
<!--End -->
The problem with the above snippet is that this applies to all the response codes so even if the Code fails with 500 Internal Server, the response passes through as is without IIS interfering. This exposes my internal Controller and View code to the user (if by chance some exception occurs that I have not handled).
So, how do I configure web.config to pass through detailed response only when response.statuscode is 600 (custom) and provide the default IIS custom pages for other errors (for example Internal Server Error 500).
If you are running in integrated pipeline mode you could try setting the TrySkipIisCustomErrors property to true:
Response.StatusCode = 600;
Response.TrySkipIisCustomErrors = true;
This being said the HTTP specification clearly defines that response HTTP status code are not superior to 5xx. So setting Response.StatusCode = 600; seems like something pretty unusual here. What exactly are you trying to achieve and why the standard HTTP response codes defined in the specification cannot cover your scenario?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With