Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.net mvc route drops numeric folder at the end of a wildcard

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?

like image 261
Scott Moore Avatar asked Dec 08 '25 10:12

Scott Moore


1 Answers

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?

like image 169
Dick Klaver Avatar answered Dec 09 '25 22:12

Dick Klaver