I have a heavy head from trying to get full programmatic control over error visualization in IIS7 (integrated mode). I want to make a mistake (page not found, internal server error, not authenticated, etc.), Transfer the entire request to custom ASPX or HTML (I prefer the latter) with the correct HTTP status code.
I want IIS7 to miss what I set for the HTTP status code. I do not need its error handling. When I set Response.StatusCode = (int)HttpStatusCode.NotFound , I do not want IIS to display its own error page, but may have passed the request to another file.
I got this static configuration:
<configuration> <system.webServer> <httpErrors> <clear /> <error statusCode="404" path="/errors/404.html" responseMode="ExecuteURL" /> </httpErrors> </system.webServer> </configuration>
While this works, it does not give me programmatic control over what to do with the answer, given the error scenario. The configuration is a good reserve, but I would really like to set Response.StatusCode and do something completely different from the configured 404.html in certain circumstances (for example, the JSON response, if we get Accept: application/json ), but IIS7 won Let me . Not by chance.
And what the hell am I supposed to do? I tried setting the HttpResponse.TrySkipIisCustomErrors Property , but it looks like a huge hack and doesn't seem to work sequentially. Is setting this property a truly truly recommended best practice to get the desired behavior?
Currently, I feel like I'm staying with her, but with intense hatred of IIS7. Can someone please help me fix this by proving that I am just stupid and that I really can completely control the HTTP stack?
AsbjΓΈrn ulsberg
source share