0

I have developed an MVC5 application for one of our client. It works fine. Now we have more clients where all the functionalities are same, but the view is different for each client(Not only the layout, but the html structure itself is different in each view).

What I was doing to distinguish the clients is to provide different urls, adding a client identifier (because we need to identify the client even before login), and filtereing it in the RouteConfig as given below:

routes.MapRoute("ClientRoute", "{client}/{controller}/{action}/{id}",
            new { controller = "Home", action = "Index", id = 
UrlParameter.Optional },
            new RouteValueDictionary 
            { 
                { "client", "icici|federal|pnb|sbi" }  
            });

where the icici,federal,pnb and sbi are the valid clients.

and I could use this below code to distinguish the clients for any client specific logic.

var clientName = HttpContext.Current.Request.RequestContext.RouteData.Values["client"].ToString();

What I want is to have separate View folders for each client

  • Views (Default, should be taken from here if not found in other locations)
  • ICICI_Views
  • SBI_Views
  • FEDERAL_Views
  • PNB_Views
  • ....

these folders will have the layout and cshtml files. Any action having return View() or return View("viewname") should pick the corresponding views from the respected client folders.

Please help me if anyone know any solution to implement this (like configuring RouteConfig or DisplayModeProvider class, etc). I dont want to have a if-else check in each return view statement and specify the full path.

Thanks in advance :)

Erik Philips
  • 53,428
  • 11
  • 128
  • 150
  • Did you look into Areas ? – Shyju Nov 14 '18 at 05:31
  • What it sounds like you want is a multi-tenant system. In which case I would recommend creating your own VirtualPathProvider. Secondly, trusting that the `client` value is correct and not altered by the users is really a bad idea. Your user should have a client ID that should determine a view, not some external source anyone could change in a browser. – Erik Philips Nov 14 '18 at 07:50
  • @Shyju, I will look into Area, but is it possible to have only views in separate area? I dont think. If even if possible how to configure when,which view to return? – user2707307 Nov 19 '18 at 12:11
  • @Erik Philips, I am not clear about VirtualPathProvider. Will check. Thanks – user2707307 Nov 19 '18 at 12:17

1 Answers1

0

You can specify the path of the view while returning from action method, For example if the client is ICICI then return View("~/ICICI_Views/Home/Index.cshtml"); and if no client found you can use return View();

return View("~/ICICI_Views/Home/Index.cshtml");
Aquib Iqbal
  • 375
  • 2
  • 9