Vikram Vikram - 20 days ago 5
ASP.NET (C#) Question

Front End Versioning the ASP.Net MVC

We've got an enterprise application running on ASP.NET MVC. We've recently started revamping the complete UI of the application. Now, when I say UI, its not simple CSS that I could put in a separate folder and load dynamically. Basically, the complete navigation structure, layout elements, everything is now being revamped. However, the overall code (controllers, models) remains pretty much same with some minor enhancements here and there. Now, we are supposed to roll out the revamped UI but at the same time also support the Old UI in parallel.

The objective is to run the new UI like

appURL/v2/
rest of the view urls remain the same.

Now, our objective is that we should not have to duplicating the controllers, models into another project.

So, what would be the best approach to serve different views globally across the application based on
/v2/
identifier for version in the URL?

Answer

Using areas you can serve different views using the same controllers. So you create a "v2" area with its own views, and route requests to "v2" accordingly:

routes.MapRoute(
    "v2_default",
    "v2/{controller}/{action}/{id}",
    new { area="v2", controller = "Home", action = "Index", id = UrlParameter.Optional })

routes.MapRoute(
    "Default",
    "{controller}/{action}/{id}",
    new { area="", controller = "Home", action = "Index", id = UrlParameter.Optional });