I defined a route for the Web Api as follows
routes.MapHttpRoute(
name: "SearchApi",
routeTemplate: "api/search/{controller}-{seopath}",
defaults: new { seopath = RouteParameter.Optional }
);
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
However, when I run it from visual studio and go to http://localhost:50356/api/search/jobs-in-Bangalore I get 404 error with the message “No type was found that matches the controller named ‘jobs-in’.”
In the book, Professional Asp.Net MVC 1.0, pg 207 {title}-{author} is given as a valid route url, so why is it interpreting “jobs-in” as a controller instead of “jobs” ?
Apparently the match is greedy. Why not define your route like: