I've been wondering about the best way to do this for a couple of days and wondered what everyone else thought.
We want to rebuild and upgrade all our companies websites to ASP.NET MVC 3 and use a common template across them all (mostly); we already have one site in MVC 3 which will be the donor site for the others.
At first I was going to just copy/paste the project, replace all the content with content relevant to each site and be done with it but this would make updating the templates/stylesheets/helpers in future more difficult - we only have a handful of websites so it isn't a huge problem though.
Idea 1
What I think I would like to do would be to have a single project containing all of the websites, possibly split off by areas to keep them separated and use routing to send the requests to various domains to the right place and to build links pointing to the right domain.
This would fit with how we're planning on linking all the websites together - essentially with a menu common to all websites listing the various companies, these would link to the companies domain containing sub-menus of items related to that specific company.
This is where it becomes tricky, in that I would need to route at domain level - so rather than routing to the company2 controller on the current domain (e.g. http://www.groupcompany.ex/company2
) I want to route requests company2's own domain - http://www.company2.ex/{controller}/{action}/{id}
.
Idea 2
Alternatively I could create projects for each site in a single solution and have a common project which hosts any helpers, CSS and JavaScript etc.
Any thoughts on which way I should be doing this, and whether my suggestions are completely crazy? (which will likely be the case).
This is a common request. What you are asking about is called Multi-tenancy. To date, I don't know of any consensus on how to achieve Multi-tenancy in MVC. There are probably as many solutions as there are questions being asked about it.
I haven't solved this problem to my satisfaction either. However, there are a number of blog entries covering this. Examples include:
http://weblogs.asp.net/zowens/archive/2010/05/26/multi-tenant-asp-net-mvc-introduction.aspx
http://codeofrob.com/archive/2010/02/01/multi-tenancy-in-asp.net-mvc-why-do-we-want-to.aspx
This is something that I think needs to be built into the framework at some point. Hopefully, that happens, or at least someone comes up with an elegant solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With