Asp.net mvc route resets the numeric folder at the end of the template

So, we have a route setting, which at the end has a wildcard to capture the path to the file, the route may look like this:

/ {browserName} / {browserVersion} / {locales} / {* PackageName}

The problem occurs when we try to use this way:

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

Which ends up being passed to the controller as packageName:

/scripts/packages/super.js

The use of the route tester program also occurs, so we will completely lose why this is so. If you replace the sixth line with 6, it will work if you add another numerical folder before it turns on, so it only appears if the last folder is a numerical one. Does anyone know why this is?

+3
source share
1 answer

I created the asp.net mvc2 project by default in VS2008 and changed the following code: In 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
        );
    }

Then I added TestController:

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

And an empty index:

<%@ 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 to site.master for the URL you specified:

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

TestController. packageName, "scripts/packages/6/super.js"

.

VS2008 MVC2 ?

+1

Source: https://habr.com/ru/post/1749657/


All Articles