How to Route /About to /Home/About

后端 未结 2 1066
故里飘歌
故里飘歌 2021-01-14 10:33

I am just getting started with ASP.NET MVC and it\'s great! However, I don\'t quite understand setting up routes.

How do I route ~/About to ~/Home/About?

/Vi

2条回答
  •  没有蜡笔的小新
    2021-01-14 10:52

    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.

提交回复
热议问题