我正在使用 WebAPI 2.0 中包含的属性路由,但无法弄清楚如何根据某些条件删除路由。我使用 映射所有路线MapHttpAttributeRoutes
,然后我想使用下一行代码删除特定路线。
// enable attribute routing support
httpConfiguration.MapHttpAttributeRoutes();
// expose the flag routes only if required
if (DisableFlagEndpoint)
{
httpConfiguration.Routes.Remove(FlagsController.RouteName);
}
但这会抛出一个NotSupportedException
. 如何删除一条路线?如果没有,还有其他方法可以实现吗?