ASP.NET MVC - Catch All Route And Default Route

后端 未结 8 1966
伪装坚强ぢ
伪装坚强ぢ 2020-11-28 04:15

In trying to get my application to produce 404 errors correctly, I have implemented a catch all route at the end of my route table, as shown below:

 routes.M         


        
8条回答
  •  日久生厌
    2020-11-28 05:04

    Ah, the problem is your default route catches all 3 segment URLs. The issue here is that Routing runs way before we determine who is going to handle the request. Thus any three segment URL will match the default route, even if it ends up later that there's no controller to handle it.

    One thing you can do is on your controller override the HandleMissingAction method. You should also use the tag to catch all 404 issues.

提交回复
热议问题