这是我的路线配置
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。您要查找的资源(或其依赖项之一)可能已被删除、名称已更改或暂时不可用。请查看以下 URL 并确保其拼写正确。
请求的 URL:/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
但显示主页?
这是怎么回事?