私はページネームを受け入れる公開Webサイトを持っています。これはコントローラとアクションにデフォルト設定されています。例えば。 http://www.mydomain.com/homepageASP.Net MVCルーティングの問題 - 私のリンクに疑問符が表示されます
また、すべてのCRUDがadminのプレフィックスでアクセスされる管理領域もあります。例えば。
<ul id="menu">
<li><%= Html.ActionLink("Home", "Details", "WebPage", new { pageName = "homepage" }, null)%></li>
<li><%= Html.ActionLink("About", "Details", "WebPage", new { pageName = "homepage" }, null)%></li>
</ul>
はもはや
http://www.mydomain.com/homepageとして表示されますが、代わりに
http://www.mydomain.com/Admin/WebPage/Details?pageName=homepage
ことができる人のヘルプ:私のような持っているリンク、私は最近、何かを変更するまでhttp://www.mydomain.com/admin/controller/action
すべてが罰金されていると私はhttp://www.mydomain.com/homepageになった今とき?
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute("AdminRoot",
"Admin",
new { controller = "Admin", action = "Index" }
);
routes.MapRoute(
"LogOn", // Route name
"LogOn", // URL with parameters
new { controller = "Account", action = "LogOn" },
new { action = "LogOn" }
);
routes.MapRoute("Account",
"Account/{action}",
new { controller = "Account", action = "" }
);
//routes.MapRoute(
// "Default", // Route name
// "{controller}/{action}/{id}", // URL with parameters
// new { controller = "Home", action = "Index", id = "" } // Parameter defaults
//);
routes.MapRoute(
"ErrorRoute", // Route name
"Error/Error404", // URL with parameters
new { controller = "Error", action = "Error404" }
);
routes.MapRoute("Admin",
"Admin/{controller}/{action}/{id}",
new { controller = "Admin", action = "Index", id = "" }
/*,new { action = "Create|Edit|Delete" }*/
);
routes.MapRoute("EventNewsData",
"Admin/{controller}/{action}/{year}/{month}",
new { controller = "Admin", action = "Index", year = 0, month = 0 }
/*,new { action = "Create|Edit|Delete" }*/
);
routes.MapRoute(
"Default", // Route name
"{pageName}/{moreInfoID}", // URL with parameters
new { controller = "WebPage", action = "Details", pageName = "homepage", moreInfoID = 0 },
new { action = "Details" }
);
routes.MapRoute("Error", "{*url}", new { controller = "Error", action = "Error404" });
}
UPDATE:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute("AdminRoot",
"Admin",
new { controller = "Admin", action = "Index" },
new { action = "Index" }
);
routes.MapRoute(
"LogOn", // Route name
"LogOn", // URL with parameters
new { controller = "Account", action = "LogOn" },
new { action = "LogOn" }
);
routes.MapRoute("Account",
"Account/{action}",
new { controller = "Account", action = "" }
);
//routes.MapRoute(
// "Default", // Route name
// "{controller}/{action}/{id}", // URL with parameters
// new { controller = "Home", action = "Index", id = "" } // Parameter defaults
//);
routes.MapRoute("Admin",
"Admin/{controller}/{action}/{id}",
new { controller = "Admin", action = "Index", id = "" }
, new { action = "Create|Edit|Delete|Index|DeleteFromIndex" }
);
routes.MapRoute("EventNewsData",
"Admin/{controller}/{action}/{year}/{month}",
new { controller = "Admin", action = "Index", year = 0, month = 0 }
, new { action = "GetCalendarData" }
);
routes.MapRoute(
"Default", // Route name
"{pageName}/{moreInfoID}", // URL with parameters
new { controller = "WebPage", action = "Details", pageName = "homepage", moreInfoID = 0 },
new { action = "Details" }
);
routes.MapRoute(
"ErrorRoute", // Route name
"Error/Error404", // URL with parameters
new { controller = "Error", action = "Error404" }
);
routes.MapRoute("Error", "{*url}", new { controller = "Error", action = "Error404" });
}
フィルHaackedの優れたルートデバッガを使用してみてください(http://haacked.com/archive/2008/03/ 13/url-routing-debugger.aspx)、あなたが期待していたよりも早くリストにマッチしていると思われます。 – Lazarus
ありがとう、ちょうど試みた。私が最初にマッチしたルートであるhttp://www.mydomain.com/homepageに行くが、リンクがまだ変わっていると指摘している場合 – Jon