快速ASP.NET路由问题

时间:2011-03-24 20:28:22

标签: asp.net-mvc routing

如何使用Global.aspx文件中的规则将此/Home/About/变为/About/

6 个答案:

答案 0 :(得分:6)

   public static void RegisterRoutes(RouteCollection routes)
    {
      routes.MapRoute(
          "About", // Route name
          "About", // URL
          new { controller = "Home", action = "About" });

      ...

    }

@Scott:谢谢。修正了它。

答案 1 :(得分:3)

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

确保它位于默认路由处理程序之前。

答案 2 :(得分:1)

添加路线:

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

由于它是硬编码的,因此您需要确保它位于具有各种参数的占位符的任何路径之前。

答案 3 :(得分:1)

在默认路线之前创建一条新路线,如下所示:

routes.MapRoute("about", "About", new { controller = "YourController", action = "About" });

答案 4 :(得分:1)

答案 5 :(得分:0)

我用过这个:

routes.MapRoute(
    "HomeActions",
    "{action}",
    new
    {
        controller      = "Home",
        action          = "Index"  // I technically don't think this is required.
    },
    new  // The second object are route constraints
    {
        action          = "Index|FAQ|ContactUs|Examples|Materials|Members" // <-- various actions on my home controller.  Any regex works here.
    });