I have an annoying problem with routes in asp.net mvc. I’ve created a custom route handler to handle XMLRPC calls to my site and I want to route this to /xmlrpc/pingback.
In global.asax.cs I have this:
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.Add(new Route("xmlrpc/pingback", null,
new RouteValueDictionary(),
new PingbackRouteHandler()));
Now the xmlrpc/pingback isn’t found, because there is no controller called xmlrpc.
If I switch the order to the xmlrpc routes comes first the xmlrpc works, but every other /controller/action routes is mapped to /xmlrpc/pingback?controller=home&action=index.
How can I create a constraint that matches every controller name except “xmlrpc”? Or is there another way of doing this?
// Joan
You could add
controller = "Fake"to the Pingback route’s defaults to prevent it from matching other routes.