我正在尝试获取XML RPC服务,如以下文章所示: http://www.cookcomputing.com/blog/archives/Implementing%20an%20xml-rpc-service-with-asp-net-mvc
除路由外,一切都很好。这与SO问题MVC route conflicts with service route
中讨论过的问题类似我的RegisterRoutes代码如下所示:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.Add(new Route("wlw/publish", new WLWRouteHandler()));
}
当我把这一行
routes.Add(new Route("wlw/publish", new WLWRouteHandler()));
在MapRoutes之前我可以访问该服务但我的正常路由不起作用。我尝试添加第四个参数:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
constraints: new { controller = "regex-for-!=-wlw" }
);
但后来我得到403 Web服务器配置为不列出此目录错误的内容。
我做错了什么?
答案 0 :(得分:0)
可以在此处找到一个很好的解决方案:http://weblogs.asp.net/jasonconway/archive/2009/10/23/include-and-exclude-constraints-in-asp-net-mvc.aspx
我将MapRoute更改为以下内容:
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "home", action = "index", id = "" },
new { controller = new ListConstraint(ListConstraintType.Exclude, "wlw") }
);