문제

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?

도움이 되었습니까?

해결책

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

MVC 4 catch all route never reached

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top