views:

51

answers:

1

So we have a route setup that has a wildcard at the end to capture a file path, the route might look like:

/{browserName}/{browserVersion}/{locale}/{*packageName}

The problem comes in when we try a path like:

/FF/3/en-US/scripts/packages/6/super.js

What ends up getting passed to the controller as packageName is:

/scripts/packages/super.js

Using the route tester program this also happens so we're at a total loss of why this is. If you replace the 6 with a string, it works, if you add another numeric folder before the 6 it does get included so it appears to just drop if the last folder is numeric. Anyone know why this is?

+1  A: 

Hi Scott

I created the default asp.net mvc2 project in VS2008 and changed the following code: In the global.asax.cs I have this code:

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

        routes.MapRoute(
            "test", // Route name
            "{browserName}/{browserVersion}/{locale}/{*packageName}",
            new { controller = "Test", action = "Index", browserName = "IE", browserVersion = "8", locale = "en-US" , packageName = UrlParameter.Optional } // Parameter defaults
        );
    }

And next I added a TestController:

public class TestController : Controller
{
    public ActionResult Index(
        string browserName, 
        string browserVersion, 
        string locale, 
        string packageName)
    {
        return View();
    }
}

And a empty Index View:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> Index </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <h2>Index</h2> </asp:Content>

for convenience I added a link in the site.master for the url you specified:

<li><a href="/FF/3/en-US/scripts/packages/6/super.js">Test</a></li>

Next I set a breakpoint in the Index action of the TestController. When I hover over the packageName parameter I see "scripts/packages/6/super.js"

So I can't reproduce the behavior you got.

Are you using VS2008 and MVC2 or other versions?

Dick Klaver
Yeah, I'm on those versions, I think it must be one of our isapi filters or something else that is stripping it out since you can't reproduce it... Have to look into it...
Scott Moore