【发布时间】:2023-03-29 11:28:02
【问题描述】:
我正在使用 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。如何删除一条路线?如果没有,还有其他方法可以实现吗?
【问题讨论】:
-
ineresting..您需要执行此操作的具体场景是什么?
-
我想禁用/删除每个环境的路由。例如,测试路由入口只需要在开发机器上,所以我只想在那里启用它并在所有其他配置中禁用它。我猜我将不得不编写一个快速过滤器来实现这一点......
标签: c# asp.net-web-api-routing asp.net-web-api2