How to Route /About to /Home/About

浪尽此生 提交于 2019-12-01 11:29:52

If you want to explicity setup a route for it, you can do something like this:

routes.MapRoute( 
            "AboutRoute", 
            "About", 
            new { controller = "Home", action = "About" }  // Parameter defaults 
    );

I think thats what you want to do? I.e. have /About handled by the home controller?

The default route (as below) handles /Home/About

    routes.MapRoute(
            "Default",                                              // Route name
            "{controller}/{action}/{id}",                           // URL with parameters
            new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
        );

In response to your comment on RM's answer - you don't actually need wildcards for that. Just do

routes.MapRoute(
    "AllToHomeController",
    "{action}/{id}",
    new { controller = "Home", action = "Index", id = "" });

Note, however, that you need to place this route at the very end of your route table (and you'll have to delete the default route), as this will catch every url that comes in.

You can use Phil Haack's Route Debugger to verify that your routes pick up urls as you expect.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!