0

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?

Rickard Liljeberg
  • 966
  • 1
  • 12
  • 39
  • 1
    How about adding your own custom view page as against the System.Web.MVC.ViewPage and handle all of this stuff in there. I have not tried this for your kind of scenario. but thought of suggesting this. – Saravanan Apr 28 '13 at 17:48
  • Hmm you might be right. That could be a good solution. Will see if I have time to test it soon! – Rickard Liljeberg Apr 28 '13 at 18:13
  • Sure Rick, do let me know the implementation. We will be creating a custom view page that inherits from `ViewPage` and in the `OnPreInit` method, we will be overriding the theme based on the tenant. – Saravanan May 04 '13 at 11:02

0 Answers0