asp.net-mvc-3multi-tenantroute-constraint

MVC3 Dynamic SubDomain Routing


First of all, I have read a lot of post relating this issue like: Asp.net MVC RouteBase and IoC , Tenant-specific routes for dynamically loaded modules , and many others.

What I want is: - Dynamically create pages like tenant1.mydomain.com, tenant2.mydomain.com, etc. - My tenants will have the same functionality but just different content, styles, title, etc.

I have tried extending RouteBase class but have read that is not a clean solution. Then I have tried creating a custom RouteConstraint like above posts recommend but not succeded.

Help me!

Thanks!


Solution

  • I have achieved this by doing two things. 1) was to provide functionality to select the correct content by providing the repositories via a factory which was handed the URL on creation. The issue here is that it might be possible to fetch the wrong data via relationships from entities that themselves don't have a tennantid field.

    2) Is a basic custom view engine which looks up the host part of the URL and would look for a client specific template (via a folder structure) if the template was found it was used, otherwise the default template is returned.

    Between these two I've got a system that delivers (in my case) multiple websites via the same bespoke CMS and product management tool.