I’m trying to set up some routes for my ASP.NET MVC 5 project.
- I defined custom routes to get nice blog post permalinks – those seem to be working fine
- I added a XmlRpc Handler (similar to how it’s done in Mads' Miniblog and Scott’s post)
Now I have some strange behavior:
/Home/About
is routed correctly/Home/Index
gets routed to/XmlRpc?action=Index&controller=Blog
/HOme/Index
works (yes I discovered that due to a typo) – I always thought routes are case insensitive?- Using
Url.Action("Foo","Bar")
also creates/XmlRpc?action=Foo&controller=Bar
This is my RouteConfig
file:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.Add("XmlRpc", new Route("XmlRpc", new MetaWeblogRouteHandler()));
routes.MapRoute("Post", "Post/{year}/{month}/{day}/{id}", new {controller = "Blog", action = "Post"}, new {year = @"\d{4,4}", month = @"\d{1,2}", day = @"\d{1,2}", id = @"(\w+-?)*"});
routes.MapRoute("Posts on Day", "Post/{year}/{month}/{day}", new {controller = "Blog", action = "PostsOnDay"}, new {year = @"\d{4,4}", month = @"\d{1,2}", day = @"\d{1,2}"});
routes.MapRoute("Posts in Month", "Post/{year}/{month}", new {controller = "Blog", action = "PostsInMonth"}, new {year = @"\d{4,4}", month = @"\d{1,2"});
routes.MapRoute("Posts in Year", "Post/{year}", new {controller = "Blog", action = "PostsInYear"}, new {year = @"\d{4,4}"});
routes.MapRoute("Post List Pages", "Page/{page}", new {controller = "Blog", action = "Index"}, new {page = @"\d{1,6}"});
routes.MapRoute("Posts by Tag", "Tag/{tag}", new {controller = "Blog", action = "PostsByTag"}, new {id = @"(\w+-?)*"});
routes.MapRoute("Posts by Category", "Category/{category}", new {controller = "Blog", action = "PostsByCategory"}, new {id = @"(\w+-?)*"});
routes.MapRoute("Default", "{controller}/{action}/{id}", new {controller = "Blog", action = "Index", id = UrlParameter.Optional});
}
And that’s the definition of MetaWeblogRouteHandler
:
public class MetaWeblogRouteHandler : IRouteHandler
{
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
return new MetaWeblog();
}
}
Basically I’d like to have the usual ASP.NET MVC routing behavior (/controller/action) + my defined custom routes for permalinks + XML-RPC handling via the XmlRpc handler only at /XmlRpc.
Since the parameters are the same that are defined in the Default
route I tried to remove the route, but without success.
Any ideas?
Update:
When calling /Home/Index
the AppRelativeCurrentExecutionFilePath
is set to "~/XmlRpc"
so the XmlRpc route is legally chosen. Something seems to be messing around with the request?
Update2: The problem fixed itself in every but one case: when starting IE via Visual Studio for Debug it still fails. In every other case it now works (yes I checked browser cache and even tried it on a different machine to be sure; IE started from VS = fail, all other combinations are fine). Anyway, since it will now work for the end user I'm satisfied for the moment ;)