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

Optional arguments issue #45

Closed brgrz closed 9 years ago

brgrz commented 9 years ago

We already discussed the optional arguments and your @Dresel solution was to do this:

        localization.ForCulture("sl-si")
            .SetRoutePrefix("objave")
            .ForController<PostsController>()
            .ForAction(x => x.List(0, 0, 0, ""), new Type[] {typeof (int), typeof (int), typeof (int), typeof (string)})
            .AddTranslation("{year}/{month}/{day}");

For the following controller action:

    [Route("list/{year}/{month}/{day}")]
    public virtual ActionResult List(int day = 0, int month = 0, int year = 0, string culture = "")

I just noticed this registers only the route that picks up URLs with complete arguments:

/sl-si/objave/2014/12/23 (content per day 23. 12. 2014)

but not

/sl-si/objave/2014/12 (content per month 12/2014)

or /sl-si/objave/2014 (content per year 2014).

Without using RL the route registration works with all these three options of URLs.

Dresel commented 9 years ago

Aren't you missing the ? within your route?

brgrz commented 9 years ago

What do you mean? Where?

[Route("list/{year}/{month}/{day}")]

No, it's a blog-like route/action. Works perfectly fine.

Dresel commented 9 years ago

I mean here: [Route("list/{year?}/{month?}/{day?}")]

http://blogs.msdn.com/b/webdev/archive/2013/10/17/attribute-routing-in-asp-net-mvc-5.aspx#optionals-and-defaults

brgrz commented 9 years ago

Ha! You were right, I completely missed it. There were still some issues particularly with interfering other routes, so I had to add :int constraints also so that it looks like this

[Route("list/{year:int?}/{month:int?}/{day:int?}")]

thanks for pointing that out

brgrz commented 9 years ago

After further investigation I found out that exactly the same setup results in route missing when using the Order parameter in the above route.

So this would work

[Route("list/{year:int?}/{month:int?}/{day:int?}")]

but this won't (missing route)

[Route("list/{year:int?}/{month:int?}/{day:int?}", Order = 1)]

where Order = 0 is used for another route/action on this controller.

Do you happen to know why would that be?

Dresel commented 9 years ago

How does the other Route look like?

brgrz commented 9 years ago

[Route("{*path}", Order = 0)]

Do you think this one picks up everything since it is *?

Dresel commented 9 years ago

For AddAsNeutralAndDefaultCultureRoute Glimpse shows

{*path} (neutral)
en/{*path} (en)
list/{year}/{month}/{day} (neutral)
en/list/{year}/{month}/{day} (en)

What routes are you missing?

And I would suggest starting with the more specific one (Order 0 for list/{year:int?}/{month:int?}/{day:int?}).

brgrz commented 9 years ago

Changing the order parameter to switch more specific route with less specific one did the trick.

I'd have less problems with route debugging if Glimpse wasn't crashing for me all the time.