1

I'm using MVC 4 with IIS 7.5. I'm trying to handle 404, 500 and other codes with my own controller and view.

However, no matter what I try, IIS overrides my settings/code and injects it's own 404 (and so on) error pages. This happens locally on dev machine with IIS Express as well as production with IIS 7.5.

Here's a combination of all I've tried so far:

  1. Used tag in web.config with redirect to my custom error view, no luck.
  2. Provided custom error handling in Global.asax. It gets there (tried 404 and 500), it does call my custom controller and view, but at the end, IIS still wins and shows its page instead of my view.

By the way, I'm trying this will extensionless url as well as .html pages. How can I get IIS to leave it alone and allow MVC to take care of these errors.

I"m out of options at this point. Any advice would be appreciated.

1 Answer 1

4

You need to override how IIS handles the error status codes. This can be done by simply modifying the <system.webServer> section in your web.config.

<httpErrors existingResponse="PassThrough" />

Full information can be found on the IIS.NET site: http://www.iis.net/configreference/system.webserver/httperrors

2
  • wow, excellent! That did it. I had no idea what that setting was. Thank you so much, works great now. Feb 26, 2014 at 4:06
  • I found it through the same pain :) Feb 26, 2014 at 19:57

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.