I created a multi tenant solution in .net mvc4 that works great. I only have one last issue left.
I created my own controller with OnResultExecuting, this is good because it allows me to deal with masterpages while still maintaining my multi-tenant capabilities (routed in custom view engine)
my code looks like so
protected override void OnResultExecuting(ResultExecutingContext filterContext)
{
var viewResult = filterContext.Result as ViewResult;
if (viewResult != null)
{
viewResult.MasterName = viewResult.MasterName == "" ? "_Layout" : (viewResult.MasterName == "IGNORE" ? "" : viewResult.MasterName);
}
My only remaining problem is that I cant make one certain page for one certain customer use a different layout.
Here is what i can do
- Have different layouts for different pages
- Have a different version of the layout for a tenant
- have no masterview (by sending in IGNORE)
But what i cannot do is replace say one view-file for customer X and have it use _LayoutX instead. where i still want all other files for customerx to use normal _Layout
because if I create a _Layout for customerX then all customerX's pages will use it, not what i wanted. If I instead create a file called _LayoutX for customerX I can then not apply it to a certain view file. Because even if I create the view file for customerX it will ignore any @Layout i put in the actual view file because it will use what it got from custom controller.
I guess what I can do is make it so that myView (globally) use _LayoutX (sent in from the controller). I can then globally put a _LayoutX that is a clone of _Layout but under customerX I can put _LayoutX that actually is the unique file i want. Not a pretty solution since I even on a global scale would get twice as many layout files to keep track of.
Any better ideas?