0

请有人对这个问题有所了解,这让我发疯!

路线:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
     "DefaultOrderingRoute", // Route name
     "{controller}/{action}/{id}/{slug}", // URL with parameters
     new { controller = "Order", slug = UrlParameter.Optional }, // Parameter defaults
     new { controller = "^Order$" }
    );

    routes.MapRoute(
      "DefaultImageRoute", // Route name
      "{controller}/{action}/{id}", // URL with parameters
      new { controller = "Image", }, // Parameter defaults
      new { controller = "^Image$" }
    );

    routes.MapRoute(
      "FooterRoute", //route for invoking actions for the Footer
      "{controller}/{action}", // URL with parameters
      new { controller = "Footer", }, // Parameter defaults
      new { controller = "^Footer$" }
    );

    routes.MapRoute(
       "DefaultDealRoute", // Route name
       "{city}/{category}/{id}/{slug}", // URL with parameters
       new { category = Deals.Globals.Global.CATEGORY_ALL_NAME, controller = "Deal", action = "Details", slug = UrlParameter.Optional }, // Parameter defaults
       new { controller = "^Deal$", id = @"\d+" }
    );

    routes.MapRoute(
        "DealRouteForCategory", // Route name
        "{city}/{category}", // URL with parameters
        new { city = "", category = Deals.Globals.Global.CATEGORY_ALL_NAME, controller = "Deal", action = "Details" }, // Parameter defaults   
        new { controller = "^Deal$" }
    );
}

我添加了对 routedebugger 的引用,以查看引擎盖下发生了什么。因此,对于选定的 URL:

http://my.SERVER.IP/VirtualDirectoryName/Order/PayPalNotify/9/blabla

URL 调试器显示以下内容:

AppRelativeCurrentExecutionFilePath: ~/Order/PayPalNotify/9/adfaf (正是我所期望的)!!!

调试器还显示路由 DefaultOrderingRoute 和 DefaultDealRoute 匹配(这是我没想到的!因为我对路由有限制!!)。

它还表明匹配的路由是:

匹配路线:{controller}/{action}/{id}/{slug}

带有路线数据:

controller:  Deal
action:      Details
id:          9
slug:        adfaf
city:        Athens
category:    All

这怎么可能??我究竟做错了什么?

PS。我注意到通过重新发布URL 正确的路由被执行!!!

4

1 回答 1

1

谜团解开了:我做了一件非常糟糕的事情(!):

在 Session_Start() 我有某处代码执行以下操作(除其他外)

    Session_Start() 
    {
// code snippet out for brevity 
//setup the city route values
    HttpContext.Current.Request.RequestContext.RouteData.Values["city"] = cityToBeginWith;
//setup the category route values
    HttpContext.Current.Request.RequestContext.RouteData.Values["category"] = Deals.Globals.Global.CATEGORY_ALL_NAME;
//setup the controller route values
    HttpContext.Current.Request.RequestContext.RouteData.Values["controller"] = "Deal";
//setup the action route values
    HttpContext.Current.Request.RequestContext.RouteData.Values["action"] = "Details";    
    }

这导致选择了“虚假”路线……非常糟糕!

于 2012-05-27T09:08:59.320 回答