我有这个功能:
protected void Application_Start()
{
Database.SetInitializer(new PersonDbInitializer());
GlobalConfiguration.Configure(WebApiConfig.Register);
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
WebApiConfig是:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
在代码中的某个时刻,我想遍历所有寄存器api路由。 知道我该怎么办?
答案 0 :(得分:0)
System.Web.Http.GlobalConfiguration
是静态的,您可以使用
GlobalConfiguration.Configuration.Routes
foreach (System.Web.Http.Routing.IHttpRoute route in GlobalConfiguration.Configuration.Routes)
{
}