I created site A successfully in sitecore and has deployed to production, now I want to add another site B to the same sitecore instance. I am aware of how to do this, but I am not sure how I can separate the two sites' code (layouts, controls etc.) so that one is not truly dependent on other. Instead of combining both the sites in the same site A project in visual studio, I was wondering if I can create a new project for site B but still reuse sitecore files that are in site A's project? What I am trying to understand really is the best practices in architecting multisite solutions in sitecore. Any ideas? Note: site A and site B are totally different in every aspect except the fact that they need to run on same sitecore instance.
2 Answers
I recommend you separate each site's assets into folders on the file system:
/Website/
/Website/sites/
/Website/sites/SiteA (<-- specific to SiteA)
/Website/sites/SiteB (<-- specific to SiteA)
/Website/sites/Common (<-- shared across any sites)
In Sitecore, do the same for your presentation components.
- layouts
- SiteA
- SiteB
- Common
- Sublayouts
- SiteA
- SiteB
- Common
And the same for templates:
Templates
User Defined
SiteA
SiteB
Common
Separate out C# class libraries too so they're specific to each site and have a common project for hared code (e.g. utility code for any site, extension methods, helper classes, etc). Visual Studio solution:
- WebApp
- SiteALib (<- SiteA specific code)
- SiteBLib (<- SiteB specific code)
- CommonLib (<- reusable code for any site)
As for the sites in the content tree, separate them out too at the same level:
sitecore
content
SiteA (<-- root item for SiteA)
home (<-- start item for SiteA)
SiteB (<-- root item for SiteB)
home (<-- start item for SiteB)
I think the simplest solution would be to just use layouts, sublayouts etc for each site.
You'd probably just have 2 folders in the layouts folder:
layouts/SiteA layouts/SiteB
they will contain the aspx & ascx files for each site. Then you'll use the same Sitecore files. You will also be able to share DLL's or other Projects in the Solution, if needed (if you have a generel Util dll or some general WebControls that you use across all your solutions).
This may not be the best way to seperate them, but it's simple.
Just remember to have seperate s in the section and also the new sites in the publish:end section of the web.config.
And remember you'll be able to access content from one site to another (ie. www.sitea.com/sitecore/content/Siteb.aspx), unless you have some code that handles that.
Another general tip is to use External URLs to link between the sites, and to avoid having Sitecore change them to internal URLs, setup an editingsite on a different domain (ie. edit.mysites.com). Because if you are editing on www.sitea.com/sitecore and insert an external url to www.sitea.com, Sitecore will "help you" and transform it into an internal URL, as the domains match.