0

我正在尝试使 XML RPC 服务运行,如以下文章所示:http: //www.cookcomputing.com/blog/archives/Implementing%20an%20xml-rpc-service-with-asp-net-mvc

一切都很好,除了路由。这与此 SO question MVC route conflict 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 The Web server is configured to not list the contents of this directory 错误。

我究竟做错了什么?

4

1 回答 1

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") }
        );
于 2013-03-27T11:57:05.113 回答