如何配置ASP.NET MVC路由以在"主页"页面上隐藏控制器名称?

Kev*_*Kev 2 asp.net-mvc routing asp.net-mvc-routing asp.net-mvc-2

继这个问题之后:

使用默认控制器的ASP.NET MVC路由

我有一个类似的要求,我的最终用户不希望在登陆的URL或他们的应用程序的"主页"中看到控制器名称.

我有一个控制器DeviceController,我想成为"主页"控制器.这个控制器有很多动作,我想使用URL如下:

http://example.com  -> calls Index()  
http://example.com/showdevice/1234 -> calls ShowDevice(int id)  
http://example.com/showhistory/1224 -> calls ShowHistory(int id)  

我还需要为此控制器生成的链接省略/deviceurl 的一部分.

我还有许多其他控制器,例如BuildController:

http://example.com/build  
http://example.com/build/status/1234  
http://example.com/build/restart/1234  

等等.这些控制器的URL很好.

问题是,即使在研究了上面提到的问题的答案之后,我似乎也无法理解这个问题.

有人可以提供一个代码示例来解释如何执行此操作吗?

我正在使用ASP.NET MVC2.

Max*_*oro 6

试试这个:

   private void RegisterRoutes(RouteCollection routes) {

      routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

      routes.MapRoute("default", "{controller}/{action}/{id}",
         new { action = "index", id = "" },
         // Register below the name of all the other controllers
         new { controller = @"^(account|support)$" });

      routes.MapRoute("home", "{action}",
         new { controller = "device", action = "index" });
   }
Run Code Online (Sandbox Code Playgroud)

例如/ foo

如果foo不是控制器,那么它被视为device控制器的动作.