I'm working on an MVC4 application that is designed to service two domains. Most of our content will be shared across the domains, but sometimes we will need to render different markup (using Razor) depending on which site the request came from.
Ideally, I want a convention-based approach that allows me to have a folder structure like this:
Views
+ Domain1
+ ControllerName
View1
View2
+ Domain2
+ ControllerName
View1
+ ControllerName
View1
View2
When resolving a view, I would like to check the domain-specific folder first, then the general views folder.
My first thoughts were to implement a custom view engine that inherits RazorViewEngine that would swap the ViewLocationFormats strings depending on the request domain. Unfortunately all this stuff is buried in the VirtualPathProviderEngine and can't be overridden.
See Question&Answers more detail:os