I currently have:
config.Routes.MapHttpRoute(
name: "AccountApiCtrl",
routeTemplate: "/api" + "/account/{action}/{id}",
defaults: new { controller = "accountapi", id = RouteParameter.Optional }
);
which sends requests / api / account / myaction to accountapi controller . (it works great :-))
However, I would prefer not to do this for every controller that I have, is there a way I can use the regex here so that I only have the declaration?
IE like this:
/ api / account / action goes to the controller: AccountApi and also / api / user / action goes to the controller: UserApi
ie something like strings:
config.Routes.MapHttpRoute(
name: "ControllerApiMap",
routeTemplate: "/api" + "/{controller}/{action}/{id}",
defaults: new { controller = "{controller}+api", id = RouteParameter.Optional }
);
source
share