Reputation: 2494
I have a custom route below and action.
[System.Web.Mvc.Route("Sites/{id:string}/Cache")]
public ResponseMessage<Result> DeleteCache ([FromUri] string id)
{
and when I got the the help page it gives three examples to use this call:
DELETE Sites/{id}/Cache
DELETE Sites/{id}
DELETE api/Sites/DeleteCache?id={id}
I'd like to keep the first one and remove the others. Is there a built in way to do this?
Here is my WebApiConfig.cs snippit....
config.Routes.MapHttpRoute(
name: "DeleteCache",
routeTemplate: "{controller}/{id}/Cache",
defaults: new { controller = "Sites", action = "DeleteCache" }
);
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
Upvotes: 2
Views: 103
Reputation: 2897
HelpPage will list every valid route for each controller. If you want a route to not apply to a specific controller you have to add contraints to the route to make it not match anymore :
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "{controller}/{id}",
defaults: new { id = RouteParameter.Optional },
constraints: new {controller = "((?!Sites).)*" }
);
This uses a negative lookahead regex to match every Controllers not named Sites
Upvotes: 1