简体   繁体   中英

IIS overriding handling of 404 and 500 http status codes in MVC

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM