我是否可以向ApiControllers(或路由)添加自定义属性或属性,以便我可以在DelegatingHandler中根据它们接收和做出决策?
也许有一些方法可以注入RouteData,我可以从中恢复我的价值:
request.GetRouteData()
我在这里看到一个MS_SubRoutes,但不知道如何修改它或如何解决这个问题。感谢帮助。 Psuedo处理程序代码低于我想要做的事情。
public class MyHandler : DelegatingHandler
{
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
// check the value of the custom property.
if (!request.Properties["MyCustomProp"].ToString().Contains("XXXX"))
{
throw new HttpResponseException(request.CreateErrorResponse(HttpStatusCode.Forbidden, HttpResponses.WorkflowServiceDisabledException));
}
// otherwise do this
return await base.SendAsync(request, cancellationToken);
}
}