I have spent the whole day trying to implement custom handler for HTTP errors. I am using MVC 5 and IIS 7. There are a lot of good suggestions HERE. Since I need to take care not only for 404 I have tried THIS option.
Ultimately I need to be able to handle all these cases
Should be able to handle all unmatched routes localhost/404_test/test/test/test/test/12/23
Should be able to handle HTTP 500 throw exception from the action
Should be able to handle all html errors for example 400. localhost/404_test/ddsa
Should be able to handle "file extension like url" localhost/404_test/test.cdd
Using the code in the provided link also by updating web.config as shown below I am able to handle all cases except "file extension like url". I am receiving blank page. It looks like IIS is overwriting response. It was the same for unmatched routes before I added
<httpErrors errorMode="Custom" existingResponse="PassThrough" >
Here is the rout map for unmatched cases :
routes.MapRoute("NotFound", "{*url}",
new { controller = "Error", action = "NotFound" });
Any suggestions how to have this implemented ? I see stackoverflow.com works exactly the way I want to have, but I have no idea how it is implemented.
Web.config
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<httpErrors errorMode="Custom" existingResponse="PassThrough" >
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" subStatusCode="-1" responseMode="ExecuteURL" path="/Error/NotFound" />
<remove statusCode="500" subStatusCode="-1" />
<error statusCode="500" subStatusCode="-1" responseMode="ExecuteURL" path="/Error/ServerError" />
</httpErrors>
</system.webServer>