开发者

asp.net MVC: how to catch a 404 error?

开发者 https://www.devze.com 2022-12-27 08:49 出处:网络
in the old days, with asp.net, when i would navigate to a non existing page, the .net framework (or iis?) would throw a 404 and i could attach a default page to that error in the web.config in the cus

in the old days, with asp.net, when i would navigate to a non existing page, the .net framework (or iis?) would throw a 404 and i could attach a default page to that error in the web.config in the custom errors section.

but in the asp.net mvc that doesn't seem to work? Does the mvc framework throws some kind of invalid route excpetion saying it can't find any开发者_开发问答 route for my uri or something like that?


In your routes registration you can add a "catchall" route after your other routes so if no route is matching the current request you can redirect it to a specific controller/action

From another answer in stack overflow:

routes.MapRoute("Error", "{*url}",
        new { controller = "Error", action = "404" }
    );
0

精彩评论

暂无评论...
验证码 换一张
取 消