HttpConfiguration MapHttpRoute different controller for request with and without QueryString

15 Views Asked by At

I am trying to support two HTTP requests as below:

  • http://localhost:80/bookstore/book/1 <== this gets the actual book (ID = 1) in binary
  • http://localhost:80/bookstore/book/1/?include=title&include=author <== this returns the title and author of book (ID = 1) in Json

I have something like this but only the bookMeta controller gets hit:

config.Routes.MapHttpRoute(
            name: "bookMeta",
            routeTemplate: "/book/{bookID}",
            defaults: new
            {
                controller = "bookMeta",                    
                bookID= RouteParameter.Optional
            }
        );

config.Routes.MapHttpRoute(
            name: "bookBinary",
            routeTemplate: "/book/{bookID}",
            defaults: new
            {
                controller = "bookBinary",                    
                bookID= RouteParameter.Optional
            }
        );

Obviously they are duplicate routes which doesn't work.

So my question is, how can I set up the MapHttpRoute to tell the above two requests to goto two different controllers (bookBinary and bookMetadata)?

0

There are 0 best solutions below