views:

115

answers:

3

I have an Asp.net Mvc site where I want to give a separate access and user interface to different clients like: http://company1.mysite.com
http://company2.mysite.com
http://company3.mysite.com

Each client will have a different ui but practically same functionality (or with some features disabled).
I'd like to separate graphics for each client like logo, css and images.

How would be the the best way to implement that?

A: 

You have to check the incoming URL and serve different CSS files for each one. You can use background images if you want to change images between companies.

Other recommendations:

  • Keep separate folders for different companies (and use the root for common things)
  • If you have to disable some functions, don't ask for the company name, but ask if it is allowed in current "profile".

    If Company = A then
       UseFunctionX = true
    else
       UseFunctionX = false
    
    
    //later in the code
    If UseFunctionX then
        // do domenthing
    

    This way adding more profiles latter is simpler

Eduardo Molteni
+1  A: 

There are a number of things you can do. The first level, as already mentioned is to use a different CSS file. You can dynamically put in a different path to your CSS file, by creating a Helper method. So it would be used something like this:

<link href="<%=AppHelper.GetCSSPath("mysite.css")%>" rel="stylesheet" type="text/css" />

This gives you some level of customization. A further level would be actually have different view files for each sub-site. You could do this by creating a new ViewEngine:

public class SubSiteViewEngine: WebFormViewEngine
{

  private string GetSiteRoot() {
   // some logic to get the site root from the incoming URL
  }

  public SubSiteViewEngine()
  {

    MasterLocationFormats = new[] { 
            GetSiteRoote() + "/Views/{1}/{0}.master", 
            GetSiteRoote() + "/Views/Shared/{0}.master" ,
            GetSiteRoote() + "/Views/Shared/MasterViews/{0}.master" 
        };
    ViewLocationFormats = new[] { 
            GetSiteRoote() + "/Views/{1}/{0}.aspx", 
            GetSiteRoote() + "/Views/{1}/{0}.ascx", 
            GetSiteRoote() + "/Views/Shared/{0}.aspx", 
            GetSiteRoote() + "/Views/Shared/{0}.ascx",
            GetSiteRoote() + "/Views/Shared/Controls/{0}.ascx" 
        };
    PartialViewLocationFormats = ViewLocationFormats;
  }

}

Hope that helps.

P.S. I'll be doing this shortly for my own project, so I should have some actual working code for it soon.

Trevor de Koekkoek
+1  A: 

Another option is to arrange this using IIS. You'll have to check the performance impact for that, but by doing that, you can control each application (or a pool) separately.

Basically, what you do is make a different website for each tenant in your system. Make it point to your application folder for the actual application code. The variable content (css, a file library perhaps? use your imagination ;-)) should then be added using a virtual directory pointing to their folder.

By using this approach you won't have the risk of having data crossover between tenants due to unexpected bugs and such.

Erik van Brakel