MVC: Routes Based on Sitemap Locations

JanL@kentico.com[email protected] Czech RepublicMember, Administrator, Kentico Staff admin
edited February 2017 in Back-end Development

One of our ideas is to allow MVC applications to reflect the sitemap and the locations of content items in it automatically.

Would you like to use such automation when creating sites?

Our initial thought is to co-develop a logic that would create stubs of action result methods. These methods would then be decorated with appropriate attribute-based routes automatically. It could be a great open-source project that could become a part of the Deliver .NET SDK.

A simple example:

The above would result in such an ActionResult method:

[Route("offices")] [Route("about-us")] public async Task<ActionResult> OfficesAboutUsPage() { }

The functionality could generate all actions into one controller or into multiple controllers.

Moreover, if you move nodes of the sitemap or if you change sitemap locations of content items in Draft, the tool could make corrections to your existing controllers and actions. It might be possible to develop such functionality with the use of the Roslyn toolset.

The main questions are:

  • How often does the sitemap change during/after the development? Why?
  • Do you usually put sections with static content to just one controller class or to multiple controllers?
  • If you spread it across multiple controllers, do you have any special patterns and practices on how to do it? (E.g. each major section has its controller.)
  • Would you prefer traditional routing (centralized in RouteConfig.cs) or attribute routing for displaying Kentico Cloud content?
  • If you prefer RouteConfig.cs, how much effort does it take to adjust the MVC project to the change of the sitemap/location of a content item?
  • What do you think about automatic adjusting of the code when sitemap or content item changes in Kentico Cloud?
  • In which ways such tool should be configurable?

Feel free to discuss the topic here! We'd love to hear if this is what you'd use in your projects. Then, we could write an article and discuss how we can improve the Deliver .NET SDK, together with the community.

Comments

Sign In or Register to comment.