这是我的路线配置
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}/",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
//routes.MapRoute(
// name: "Default2",
// url: "{controller}/{action}/",
// defaults: new { controller = "Home", action = "Index" }
//);
}
如果我输入
http://localhost:62378/thiscontrollerdoesnotexist
它给了我这条消息
>'/'应用程序中的服务器错误。 无法找到该资源。 说明:HTTP 404.您要查找的资源(或其中一个依赖项)可能已被删除,名称已更改或暂时不可用。请查看以下网址,确保拼写正确。请求的网址:/ thiscontrollerdoesnotexist
但如果我改变我的路线
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controllerhithere}/{action}/{id}/",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
//routes.MapRoute(
// name: "Default2",
// url: "{controller}/{action}/",
// defaults: new { controller = "Home", action = "Index" }
//);
}
我将{controller}更改为{controllerhithere}。现在当我输入
http://localhost:62378/thiscontrollerdoesnotexist
我需要
http://localhost:62378/thiscontrollerdoesnotexist
但显示主页?
这是怎么回事?
答案 0 :(得分:0)
此项目:http://www.codeproject.com/Articles/299531/Custom-routes-for-MVC-Application#premain7
允许您将以下行添加到global.asax
RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
这将允许您调试路由,您可以确定匹配的内容和覆盖的内容。