0

It is possible to set the "Routehandler" as a attributes on the controller class or the controller methods?

Like this

[RoutePrefix("api/cart")]
//[RouteHandler(new CustomRouteHandler())] ???????
public class CartController : ApiController
{
    private readonly CartRepository _repository;

    public CartController()
    {
        _repository = new CartRepository();
    }
 }

Or something like this

  [HttpGet]
  [Route(Name = "api/{controller}")]
  //[RouteHandler(new CustomRouteHandler())] ?????
  public Cart Hest() 
  {
       return _repository.Get();
  }

The only place i can seem to set the RouteHandler is in the config like this.

RouteTable.Routes.MapHttpRoute(
                name: "test",
                routeTemplate: "{controller}/{action}",
                defaults: new { action = RouteParameter.Optional }
                ).RouteHandler = new CustomRouteHandler();

Any ideas?

MacGyver
  • 6,579
  • 1
  • 18
  • 11
  • Possible duplicate of [set web api route handler when using route attributes](http://stackoverflow.com/questions/33542991/set-web-api-route-handler-when-using-route-attributes) –  Nov 06 '15 at 13:42
  • @Amy - It acutaly is. I just thought i asked the question in a too complex/broad way and here im trying to pinpoint it. Should i delete the other? – MacGyver Nov 06 '15 at 15:23
  • The community preferred way of handling things like this is to edit the original question to make it clearer. –  Nov 06 '15 at 15:51

0 Answers0