I have a following route:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{service_name}/{controller}/{id}",
defaults: new { service_name = "identity", id = RouteParameter.Optional }
);
I want this route to work only with following pattern (service name should always be identity):
api/identity/{anyController}/{id}
Now I could accomplish this by simply changing my route template to
routeTemplate: "api/identity/{controller}/{id}",
but then I would not be able to read "service_name" from Request.GetRouteData(); since it's not named parameter.
Is there a simpler way to do this, rather than creating an ActionFilter which will filter all requests who's service name is not "Identity" in this case.
api/identity, when you try to check service_name in the RouteData dictionary, there is no entry withservice_namekey.RoutePrefixattribute above your Controller. like[RoutePrefix("api/identity")]and then use[Route("{id}")]above your Action. Its make your Url likeapi/identity/id?id=