【问题标题】:Route for XMLRPC Service breaks default routeXMLRPC 服务的路由打破了默认路由
【发布时间】:2013-03-27 08:10:52
【问题描述】:

我正在尝试使 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 The Web server is configured to not list the contents of this directory 错误。

我做错了什么?

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-4 xml-rpc


    【解决方案1】:

    可以在这里找到一个很好的解决方案: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") }
            );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-17
      • 1970-01-01
      • 2016-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多