1

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?

2
  • 4. What data are we talking about?
    – Alexander
    Jan 27, 2014 at 12:48
  • @Alexander a template file (mostly just html) with a file dependency cache
    – kiwijus
    Jan 27, 2014 at 13:44

2 Answers 2

1

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.

2
  • for point 2 is there any advantage/disadvantages for doing it as a single application pool? For claims based authentication would something like WIF work?
    – kiwijus
    Jan 27, 2014 at 13:45
  • WIF should work and does not care about (2). Multiple AppPools can be necessary, if you have database-Level Access rights and use Windows auth for the db Server. Same for other resources.
    – TGlatzer
    Feb 3, 2014 at 8:17
0
  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.
1
  • Is there any advantage to using a custom HTTP Module over using a base controller?
    – kiwijus
    Jan 27, 2014 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.