Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi tenancy in ASP MVC

Yet another multi tenancy post im afraid. I just cant find a good solution to my problem, I have read all the great posts on multi tenancy for ASP MVC but I still need some good advice.

Im going to create a corporate presence for one of my customers. Their company structure is like a main company (ex. Acme Group Ltd.) which own several other companies (ex. Acme Holding Ltd, Acme Technology Ltd., Acme Maritime Ltd., etc.).

I want to use one ASP MVC project to serve as the container for all the sites to cut down on the code needed and to keep it DRY. I also want all the sites to use the same Membership DB.

My first thought was to make one controller folder for each sub-company and one root controller for the corporate main page. Then it would look like:

acme.com ("Corporate main page")
acme.com/Holding ("Acme Holding Ltd.")
acme.com/Maritme ("Acme Maritme Ltd.")
...

This structure is fine by me, but I also want the users of the website to access each sub-site based on their own separate domains, ex:

holding.acme.com (This should direct to "acme.com/Holding").
...

That would of course also work, but the thing is that I do not want the url to change when the user is directed to "acme.com/Holding". I would like it to still be "holding.acme.com", "holding.acme.com/About", "holding.acme.com/Contact", etc. instead of "acme.com/Holding/Contact", etc.

What would be the best practice to use in this particular project, any thoughts?

like image 944
Martin at Mennt Avatar asked Jan 12 '10 19:01

Martin at Mennt


2 Answers

Keep it simple, use IIS URL Rewrite Module. You can set it up to rewrite acme-holding.com/* URLs to acme.com/Holding/*:

<rewrite>
    <rules>
        <rule name="Forward to acme.com">
            <match url=".*" />
            <action type="Rewrite" url="http://acme.com/Holding/{R:0}" />
        </rule>
    </rules>
</rewrite>
like image 188
Pavel Chuchuva Avatar answered Oct 20 '22 15:10

Pavel Chuchuva


I wrote a blog on multi-tenancy that covers exactly what you are attempting here.:

http://jasonjano.wordpress.com/2010/02/22/multi-presentation-websites-for-c/

Good luck!

like image 1
Jason Avatar answered Oct 20 '22 15:10

Jason