Imported from the CodePlex archive for reference purposes. Support for MvcCodeRouting has ended.
In this case, do you want all routes to start with my-blog, or just
routes for this controller ?
I think you can still achieve what you need by manually adding routes before or after your call to routes.MapCoudeRoutes. Here is a basic example:
//makes BlogController.SomeAction available at the url "my-blog/do-something". routes.MapRoute("blog-do-something", "my-blog/do-something", new { controller = "Blog", action="SomeAction"}); //MvcCodeRouting generates routes here routes.MapCodeRoutes(typeof(HomeController).Namespace, new CodeRoutingSettings { DefaultAction = "Index" });
What I've been thinking for a while now is having a base route setting
(need to think about the name since we are already using BaseRoute for
the namespace part of the route).
So, you could do something like:
routes.MapCodeRoutes("Site", new CodeRoutingSettings { BaseRoute = "my-blog" });
That way all routes would start with "my-blog"
Ah yes, totally forgot about the ActionName attribute. Thanks.
For my use case it'll be all routes will start with my-blog. Your solution for a base route setting makes sense to me.
What do you think of this as an additional way to declare base routes?
[RouteName("my-blog", NameSpaceBaseRoute: true)] class BlogController : Controller
I know it doesn't make sense in a multiple controller per namespace scenario but the flexibility seems useful - at least for my usage!
I generally prefer attribute routing rather than since most of my routes have hyphens and knowing the routes/constraints on top of the action is useful.
control of the person that configures routing for the app, and not the
person who writes the controller. Usually they are the same person,
but I want to support plugin scenarios, e.g. a blog service written by
a 3rd party.