I'm running my MVC 3 app (recently updated from 2) on IIS 7.5 (Win 7 64bit) with a .NET 4.0 integrated pipeline app pool and have the following set-up in web.config:
<customErrors mode="On" defaultRedirect="~/Problem/Oops" redirectMode="ResponseRedirect">
<error statusCode="404" redirect="~/Problem/NotFound" />
</customErrors>
If an action method on a controller throws an exception the server and hence generates a 500 errorcode it correctly sends the browser to the default redirect URL.
However if my action deliberately returns a HttpNotFoundResult via HttpNotFound() I get the IIS 7.5 404.0 error page and not the one indicated in my web.config.
If I enter a URL that doesn't exist on my app like http://localhost/MyApp/FOO then I do get shown the page as indicated by the web.config.
Anybody have any ideas why I'm not getting redirected to my custom 404 error page when using HttpNotFound()?
Please try below syntax instead of calling HttpNotFound and let me know the result ;)
throw new HttpException(404, "NotFound");
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