如何编写强制单个控制器/操作的路由?

时间:2013-09-11 19:19:19

标签: c# asp.net-mvc routes

我正在尝试创建一个临时网站,基本上将其锁定以显示单个控制器操作。

我尝试了这个,但它不起作用:

routes.MapRoute(
  name: "Test",
  url: "Test/Index"
);

这是我在RouteConfig.RegisterRoutes方法中的所有内容,而不是:

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

当我加载页面时,我得到:

HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly. 

1 个答案:

答案 0 :(得分:1)

我认为你在寻找

routes.MapRoute(
  name: "Default",
  url: "{*url}",
  defaults: new { controller = "Test", action = "Index"});

使用Index。方法强制对TestController的所有请求。