Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It depends on how you plan on implementing multitenancy (eg. using authorization with common urls, subdomains, custom domains, or any combination). But you should be able to do just about any approach with Azure and MVC2. If you plan on using a custom domain for each tenant, versus a subdomain, you will need to be happy with using CNAME entries (not A records) to point each custom domain to Azure but that usually is not a problem.</p> <p>MVC offers many extension points where you can implement multitenancy in its various flavors. The main goal is to uniquely identify the user by either a login or the url.</p> <p>We have an MVC2 application running in Azure that parses the request url to differentiate the tenant. There are many ways to do this. We took the approach of extending the <strong>Controller</strong> class to provide our app with the unique tenant information so we could use it as needed to make appropriate repository calls to display the proper views etc.</p> <p>Here is a sample of what a MultiTenant Controller might look like:</p> <pre><code>public class MultiTenantController : Controller { public string TenantCode { get; set; } protected override void OnActionExecuting(ActionExecutingContext filterContext) { TenantCode = GetTenantCode(filterContext.HttpContext.Request); } private string GetTenantCode(System.Web.HttpRequestBase request) { string host = new RequestParser(request.Url.AbsoluteUri).Host; return _tenantService.GetTenantCodeByHostAddress(host); } } </code></pre> <p><strong>NOTES:</strong></p> <ol> <li>The <strong>RequestParser</strong> function above is just any implementation that knows how to parse urls in a safe manner.</li> <li><strong>_tenantService</strong> can access some kind of persistent store (Azure Tables in our case) to get the TenantCode from the host address in the url.</li> </ol> <p>All of your controllers would inherit from the above class. Then, to differentiate between tenants you just refer to the <strong>TenantCode</strong> within your controller like so:</p> <pre><code>public class HomeController : MultiTenantController { ... public ViewResult Index() { var vm = _homeService.GetHomePageViewModelForTenant(TenantCode); return View(vm); } } </code></pre> <p>Using the above implementation you could serve different sites or data to urls like the following:<br> <a href="http://subtenant1.yourdomain.com" rel="noreferrer">http://subtenant1.yourdomain.com</a><br> <a href="http://subtenant2.yourdomain.com" rel="noreferrer">http://subtenant2.yourdomain.com</a><br> <a href="http://www.customtenantdomain.com" rel="noreferrer">http://www.customtenantdomain.com</a></p> <p>Your backend store (eg. Table Storage) just needs to cross reference host names with the tenant like the table below. In the code above <strong>GetTenantCode</strong> would access the data.</p> <pre><code>HostName TenantCode ---------------------- -------------- subtenant1 Tenant1ID subtenant2 Tenant2ID www.customtenantdomain Tenant3ID </code></pre> <p>For www.customtenantdomain.com to work, the tenant needs a CNAME entry for www in their DNS records for customtenantdomain.com that points to your Azure Web Role's address.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload