Question

I am attempting to create a Multi tenant SaaS site and have been reading a lot of topics around the subject, however there are still some things I'm unsure about.

  1. Most of the examples use Request.Url.Host in order to determine the tenant. The question is where is the best place to check the tenant, would this be in the Controller constructor or in the global.asax? As this needs to be checked for every request I'm guessing the tenant/host mapping should be stored in a hashtable somewhere?

  2. How does IIS and Application Pools fit into all of this, do I still need an IIS site + application pool for each of my tenants but point the phsycial path to the same location? or will I just require a single site + application pool?

  3. For Authentication on each of the tenants sites, I'm guessing we just need to set the cookie to be the tenants domain/subdomain?

    HttpCookie cookie = FormsAuthentication.GetAuthCookie(username, true); cookie.Domain = "subdomain.domain.com"

  4. How would you go about caching data for a particular tenant? HttpRuntime.Cache["CacheData"] would this cache not be available for every tenant?

Was it helpful?

Solution

Just some thougts about that all here:

  1. Request.Url.Host is fine. You can use Global.asax or an own (Abstract) base controller (I always call this ControllerBase). I'd not recommend you to use it in each and every controller you write - try to put everything necessary in some kind of configuration-Class and load it on application Start or on Demand in BaseController - you can change the Constructor of such an base class to take an identifier for the tenant.

  2. You can do both - It will probably be easiest, if you just add bindings to a single site and application pool.

  3. That's one approach to that, but you could also do some sort of claim based authentication, which contains the target tenant(s)

  4. You can create a caching, which is dependent on you tenant (as you can define caching which is dependent on the logged on user.

OTHER TIPS

  1. I'd rather write a custom HTTP Module.
  2. Better use one app pool, since you don't want to go into your configuration for each new customer.
  3. Yes.
  4. Yes.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top