Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Unexpected Url.Action output with areas #3340

Closed
Muchiachio opened this issue Oct 17, 2015 · 6 comments
Closed

Unexpected Url.Action output with areas #3340

Muchiachio opened this issue Oct 17, 2015 · 6 comments

Comments

@Muchiachio
Copy link
Contributor

Muchiachio commented Oct 17, 2015

This is basically the same as #2859, it works without areas, but doesn't always work then area is used
Again this works as expected in MVC5
Given routing in beta8:

app.UseMvc(routes =>
{
    routes.MapRoute(
        "DefaultPartArea",
        "{part}/{area:exists}/{controller}/{action}/{id?}",
        new { controller = "Home", action = "Index" },
        new { part = "second" });

    routes.MapRoute(
        "DefaultArea",
        "{area:exists}/{controller}/{action}/{id?}",
        new { part = "first", controller = "Home", action = "Index" },
        new { part = "first" });

    routes.MapRoute(
        "DefaultPart",
        "{part}/{controller}/{action}/{id?}",
        new { controller = "Home", action = "Index" },
        new { part = "second" });

    routes.MapRoute(
        "Default",
        "{controller}/{action}/{id?}",
        new { part = "first", controller = "Home", action = "Index" },
        new { part = "first" });
});

And calling this from a controller in area with part = first

@Url.Action("Index", new { part = "second" })

results in

{empty}

while expected output is

/second/admin/accounts

Another strange thing is that it can form a normal url then changing from second part to first one

@Muchiachio Muchiachio changed the title Unexpected Ur.Action output with areas Unexpected Url.Action output with areas Oct 17, 2015
@Eilon
Copy link
Contributor

Eilon commented Nov 6, 2015

@ajaybhargavb please take a look.

@ajaybhargavb
Copy link
Contributor

Thanks for reporting this and for the repro. I tried this scenario. I can confirm that there is a difference in behavior from MVC 5. Area is not picked up from AmbientValues if a segment before that has changed. MVC 5 did something different in this case. We are discussing what we should do about this scenario.

@ajaybhargavb
Copy link
Contributor

cc' @Eilon @danroth27 @rynowak

@Eilon
Copy link
Contributor

Eilon commented Nov 10, 2015

Hmm interesting. Yeah I do vaguely recall some special codes in MVC for areas. Though, if I had to guess, I'd be very surprised if that code didn't inadvertently bring this behavior to URL generation. It certainly seems to "violate" a behavior of URL generation, which is to invalidate ambient values that come after a changed parameter... but yes, let's discuss in person.

@rynowak
Copy link
Member

rynowak commented Nov 10, 2015

Yeah I do vaguely recall some special codes in MVC for areas.

http://aspnetwebstack.codeplex.com/SourceControl/latest#src/System.Web.Mvc/RouteCollectionExtensions.cs

Yep. This thing again. It almost destroyed Orchard.

@ajaybhargavb
Copy link
Contributor

We discussed about this. It looks like the current area behavior in MVC 5 was not the intended behavior. We have decided not to bring back the same behavior in MVC 6. To make this work you need to explicitly specify the area in the route values.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants