ASP .Net 自定义路由不起作用。
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
//default route
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Account", action = "LogOn", id = UrlParameter.Optional } // Parameter defaults
);
//custom route
routes.MapRoute(
"Admin",
"Admin/{addressID}",// controller name with parameter value only(exclude parameter name)
new { controller = "Admin", action = "address" }
new { addressID = @"\d+" }
);
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
public ActionResult address(int addressID = 0)
{
//code and redirection
}
在这里,如果可能,我想隐藏 url 中的所有内容......就像我想尽可能隐藏操作名称和参数名称和值......建议我这样做的可能方法
就像我想要这样的 URL(基于优先级)
1.http://localhost:abcd/Admin
或 2.http://localhost:abcd/Admin/address
或 3.http://localhost:abcd/Admin/1
或 4.http://localhost:abcd/Admin/address/1