Base Route

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

Commented on

I have a base route "xx/{xx_xx}" but how do I catch requests that do not match the route like my_site/, currently this returns a 404. 

Commented on link

So far I using two code routes one with the base rout and one without, in the code route with the base route I have now added RootOnly which seems to be the way to do it.

 settings: new CodeRoutingSettings
     {
                UseImplicitIdToken = true,
                RootOnly = true
            });
Commented on link

Yes, that's one way to do it, and the simplest one.

The other is to use the CustomRoute attribute on the controller, like this:

[CustomRoute("xx/{xx_xx}/{controller}")]
public abstract class MyBaseController : Controller {

   [FromRoute]
   public string xx_xx { get; set; }

   protected override void Initialize(ControllerContext context) {
      base.Initialize(context);
      this.BindRouteProperties();
   }
}

public class MyController : MyBaseController { }
I think the above should work but I'm not 100% sure.

Commented on link

How would this work with nested controllers, when I create a nested controller the namespace still effects the url even with an updated custom route. I expected the child controller to take on the parents custom route as the base.

namespace Controllers.yy

{

[CustomRoute("xx/{xx_xx}/x/{controller}")]

}

which produces this  yy/xx/{xx_xx}/x/{controller}/{action}

when I expect this xx/{xx_xx}/x/{controller}/{action}

Commented on link

Right, forgot about that. CustomRoute on the controller is not suited for what you need, MapCodeRoutes is the way to go.