Default route with baseRoute

Imported from the CodePlex archive for reference purposes. Support for MvcCodeRouting has ended.

Commented on

It's strange trouble with trying to define route "" with routes.MapRoute when using MCR and baseRoute:

            routes.MapCodeRoutes("{year}/{quarter}", typeof (HomeController),
                                 new CodeRoutingSettings
                                     {
                                         RouteFormatter = RouteFormatter
                                     });
            routes.MapRoute("Default", "", new { controller = "Redirect", action = "Index" });

I want to redirect from base application URL to the actual (setting in DB) quarter, 'www.my.app' -> 'www.my.app/2011/4'. But, I can't build url using MVC classes in any combinations - it's always return null. It seems to CodeRoute is very special route, and classic Url.Action("Index", "Home", new { y = 2011, q = 3}) doesn't work...

Can you help me?

Commented on link
You have to do this:

Url.Action("Index", "Home", new { y = 2011, q = 3, __mvccoderouting =
"{year}/{quarter}" })

Actually, that's a terrible name, so in the latest revision I've
changed it to this:

Url.Action("Index", "Home", new { y = 2011, q = 3, __routecontext =
"{year}/{quarter}" })

Another thing you have to be careful with, if the current route is not
CodeRoute then the special controller reference syntax won't work, so
instead of this:

Url.Action("", "~SomeController")

.. you have to do this:

Url.Action("", "SomeController", new { __routecontext = "baseRoute" })
Commented on link

__routecontext helps, thanks!

Commented on link
The code below appends __routecontext in the query string, is this normal?
Url.Action("", "SomeController", new { __routecontext = "baseRoute" })
Commented on link
No, probably matching a route not created by MvcCodeRouting, is that the case?
Commented on link
All my routes were created by MvcCodeRouting.

My project is MVC4 targeting .Net Framework 4.5

No one else is having the problem, I might be missed something.
Commented on link
So, the generated URL is correct except __routecontext is in the querystring?
If all routes are created by MvcCodeRouting, why are you using __routecontext? It's a workaround for special cases. It still should work, so maybe there is an issue.
Could you please try to reproduce by changing the target to .NET 4.0