众所周知,路由映射在Global.asax
文件中,例如:
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 }
);
}
有一个方法/类,我可以通过提供路由名称来访问路由 url 属性名称?
例如,对于Default
,我想调用类似
public object[] GetRoutePropertiesByName(string name) {
// process here the `controller`, `action`, `id` // there might be also other values
}