How to correctly and easily handle 404 errors on my MVC2 application?
Similar question: Link
The question above is partly what I'm looking for except that it seems very VERY verbose instead of being MVC2-ey. Maybe with MVC2 there is a simpler more 'convention over configuration' a开发者_如何学Pythonpproach?
How can I easily set up my MVC2 application to show a particular 404 page when a user types in a non-existant view?
Thank you.
In Web.config
<customErrors mode="On" defaultRedirect="~/Error-Page/Index">
<error statusCode="404" redirect="~/Error-Page/NotFound"/>
<error statusCode="403" redirect="~/Error-Page/BadRequest"/>
</customErrors>
There is a really easy way that might help:
In Web.config
<customErrors mode="On" >
<error statusCode="404" redirect="404.html" />
<error statusCode="500" redirect="500.html" />
</customErrors>
I put 404.html and 500.html but you could put any link to any controller/action.
It's my experience, that there really isn't a simple way to do this (adding custom errors to web.config just doesn't cut it, mainly because MVC always (or almost always) returns 500 on any unsuccessful request). The link you posted is pretty much the best way, tho it has some variations (for example you can handle 404 exceptions with an attribute instead of modifying the controller factory).
Setup a redirect 404 handler to your custom url on your favourite webserver. also you have to return a proper 404 status header from your view
精彩评论