Dresel / RouteLocalization

RouteLocalization is an MVC and Web API package that allows localization of your attribute routes.
MIT License
67 stars 13 forks source link

Get RouteValues from url string #71

Closed speakertrading closed 6 years ago

speakertrading commented 6 years ago

Hello

I'm trying to get route values from url string. Before use your library, I can do it with this code:

RouteTable.Routes.GetRouteData(new RewritedHttpContextBase(url))

Where RewritedHttpContextBase is:

    private class RewritedHttpContextBase : HttpContextBase
    {
        public RewritedHttpContextBase(string appRelativeUrl)
        {
            this.Request = new MockHttpRequestBase(appRelativeUrl);
        }

        public override HttpRequestBase Request { get; }

        private class MockHttpRequestBase : HttpRequestBase
        {
            public MockHttpRequestBase(string appRelativeUrl)
            {
                this.AppRelativeCurrentExecutionFilePath = appRelativeUrl;
            }

            public override string AppRelativeCurrentExecutionFilePath { get; }

            public override string PathInfo => string.Empty;
        }
    }

I always receive the same controller: one with "*permalink" that match with many urls. This controller is defined in RouteConfig:

        routes.MapRoute(
            "WebRoute",
            "{culture}/{*permalink}",
            new { controller = "Webs", action = "Index" },
            new { culture = CultureConstraints }

The other routes are defined with RouteAttribute and never returned with GetRouteData.

I'm trying with other modes for get RouteValues from url string but with the same result.

Do you know how to get route values including RouteAttribute routes?

Thanks

Dresel commented 6 years ago

Does it work when you don't register the "*permalink" via routes.MapRoute? Maybe it's just an ordering issue. Can you upload a repo so I can reproduce this?

speakertrading commented 6 years ago

Yes, changing order resolve the problem.

Thank you so much