__Scenario__:
User likes to register a per-route message handler for the Delete Customer action in the following controller.
```
[RoutePrefix("api/Customers")]
public class CustomersController : ApiController
{
[HttpDelete("{id}")]
public string Delete(int id)
{
return "DeleteCustomer with id " + id;
}
}
```
__Issue__:
HttpDirectRoute doesn't have a constructor which accepts HttpMessageHandler. I need this as the Handler property on HttpRoute (which HttpDirectRoute derives from) has a 'private set'
For reference, before the recent addition of HttpDirectRoute, we could add the per-route message handler like below:
```
public class CustomHttpRouteBuilder : HttpRouteBuilder
{
public CustomHttpRouteBuilder(HttpConfiguration configuration)
{
this.Configuration = configuration;
}
public HttpConfiguration Configuration { get; private set; }
public override IHttpRoute BuildHttpRoute(HttpRouteValueDictionary defaults, HttpRouteValueDictionary constraints, string routeTemplate)
{
if (defaults["controller"].ToString().ToLowerInvariant() == "customers" &&
defaults["action"].ToString().ToLowerInvariant() == "delete")
{
return new HttpRoute(routeTemplate, defaults, constraints,
dataTokens: null,
handler: HttpClientFactory.CreatePipeline(new HttpControllerDispatcher(Configuration),
new DelegatingHandler[] { new DeleteCustomerRouteDelegatingHandler() }));
}
return base.BuildHttpRoute(defaults, constraints, routeTemplate);
}
}
```
Register the custom route builder with configuration:
```
config.MapHttpAttributeRoutes(new CustomHttpRouteBuilder(config));
```
__Workaround__:
User has to create a custom route type deriving from HttpRoute, which accepts HttpMessageHandler and also mimic the functionality of HttpDirectRoute within it. User can then return the custom route type based instances when HttpRouteBuilder is building the routes.
Comments: Hi! I do not see how action filters can be used instead of per route handlers. If you have certain controllers that you want a special handler pipeline for, for example based on a specific route prefix, how can action filters solve that? My need is for the request to follow a special message handler sequence when the relevant controllers have a specific route prefix. In other words, I have a special set of message handlers for a subset of my controllers. This means that currently, to my understanding, attributed routing cannot be used. If that is true, it is really sad. Regards, Jan Ove Halvorsen
User likes to register a per-route message handler for the Delete Customer action in the following controller.
```
[RoutePrefix("api/Customers")]
public class CustomersController : ApiController
{
[HttpDelete("{id}")]
public string Delete(int id)
{
return "DeleteCustomer with id " + id;
}
}
```
__Issue__:
HttpDirectRoute doesn't have a constructor which accepts HttpMessageHandler. I need this as the Handler property on HttpRoute (which HttpDirectRoute derives from) has a 'private set'
For reference, before the recent addition of HttpDirectRoute, we could add the per-route message handler like below:
```
public class CustomHttpRouteBuilder : HttpRouteBuilder
{
public CustomHttpRouteBuilder(HttpConfiguration configuration)
{
this.Configuration = configuration;
}
public HttpConfiguration Configuration { get; private set; }
public override IHttpRoute BuildHttpRoute(HttpRouteValueDictionary defaults, HttpRouteValueDictionary constraints, string routeTemplate)
{
if (defaults["controller"].ToString().ToLowerInvariant() == "customers" &&
defaults["action"].ToString().ToLowerInvariant() == "delete")
{
return new HttpRoute(routeTemplate, defaults, constraints,
dataTokens: null,
handler: HttpClientFactory.CreatePipeline(new HttpControllerDispatcher(Configuration),
new DelegatingHandler[] { new DeleteCustomerRouteDelegatingHandler() }));
}
return base.BuildHttpRoute(defaults, constraints, routeTemplate);
}
}
```
Register the custom route builder with configuration:
```
config.MapHttpAttributeRoutes(new CustomHttpRouteBuilder(config));
```
__Workaround__:
User has to create a custom route type deriving from HttpRoute, which accepts HttpMessageHandler and also mimic the functionality of HttpDirectRoute within it. User can then return the custom route type based instances when HttpRouteBuilder is building the routes.
Comments: Hi! I do not see how action filters can be used instead of per route handlers. If you have certain controllers that you want a special handler pipeline for, for example based on a specific route prefix, how can action filters solve that? My need is for the request to follow a special message handler sequence when the relevant controllers have a specific route prefix. In other words, I have a special set of message handlers for a subset of my controllers. This means that currently, to my understanding, attributed routing cannot be used. If that is true, it is really sad. Regards, Jan Ove Halvorsen