Pregunta

I have implemented custom error pages in an MVC4 application. Basically I've added the following to my Web.Config file:

<customErrors mode="On" defaultRedirect="Error">
  <error statusCode="404" redirect="~/Error/NotFound"/>
  <error statusCode="500" redirect="~/Error/Index"/>
</customErrors>

Unfortunately, if someone uses a request that adds a path to a route the redirect doesn't take place. For example I have a Document method that takes an ID on the controller Content. The following request is valid:

/Content/Document/1

I get the 404 displayed when someone calls an url like this:

/BlaBla
/Content/BlaBla

Some users manage to add /BlaBla after the ID:

/Content/Document/1/Blabla

This is the case where my custom 404 page is not shown. How can I handle this?

¿Fue útil?

Solución

A CatchAll - Route solved the problem. A question with an answer which made me find the solution:

MVC 4 catch all route never reached

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top