Sitecore Multisite Basics
In a small city, there used to be a company. Where two guys used to work. Mr. Enthu (a.k.a. Mr.E) and Mr. Basic (a.k.a. Mr.B). As name suggests Mr.E was always enthusiastic about anything. Whenever he used to see something new, He used to go to his friend. Mr. Basic. Again as name suggests Mr. B was always clear with his basics. And when anyone used to come to his with questions. He was explaining that person with all the basic information he had!
One fine morning, Mr. E came to Mr. B and asked a question “How Sitecore resolves Multiple websites?”, and as per tradition Mr. B explained Mr.B in detail about Sitecore Multisite resolution process and this post shares those details with you!
Disclaimer — All characters in this publication are entirely fictitious and any resemblance to real persons, living or dead, is purely coincidental.
This question is special to me. Because, When I was learning Sitecore before 5-6 years back. And I asked same question to someone. And he denied to help me understand how it works? And then the journey began! I not only found out, How Sitecore Multisite works. But during this journey, I explored Sitecore a lot, and till today it never stopped! So, good to remember :
I am thankful to all those who said “no” to me. because of them, i did it myself. by Albert Einstein
Before, we go and share Mr.B’s details. Let’s understand more about question. Most of the time. You will have multiple websites in your Sitecore. Most of us know how to make this work. i.e. Add Bindings, Add entries in SiteDefinition.Config etc. And If you search on web, you will find following nice articles to get you started with Sitecore Multisite:
These all links are great place to start! But none of them covers “How it works?!”. As we are engineers we always ask “How do they do it?”. Because we know nothing is automatic in this world! Someone somewhere programmed to make it work! And to lay man it looks like it’s automatic!
Sorry being off track, let’s go back to Mr. E and Mr.B’s talk. Mr. B started drawing and he shared following drawing with Mr.E.
Mr.B said : My dear friend E, I would have been able to explain you by words. But as picture is worth a thousand words. I thought to diagram this for you. Let me help you to understand it.
It covers everything from a User requesting a host (www.X.com), till Sitecore resolves it and renders it. Please see the numbers on lines. Just follow them, and read following description. It will answer all your questions:
- Browser tries to resolve Web Server IP from Host-name (Good read :
- As shown in 1.a it tries to resolve it from Host file first (To be honest, I haven’t found any article. Whether it goes first to Host file or DNS — So, Happy to be corrected here!). That’s why while working in local environment. When your Site is hosted in local and you would like that host-name to be resolved to your local box. You do entry in Hosts file
- Then it goes to DNS Server – 1.b Indicates that
- Now, Server has IP address of Web server. If it is in local (see 2.a) then it will be connected to local web server else it will go on remote web server (see 2.b). Opens connection on Port 80 – Default Port of Web Server
- Now, we’ve reached to IIS. But on IIS there are multiple websites. e.g. X,Y,Z. Which website to use? And that’s where — IIS Bindings comes in to rescue. It checks requested host-name with bindings. And matched website gets control
- Now, Control goes to ASP.NET and then it comes to Sitecore:
- Site Resolution happens using Sitecore.Pipelines.HttpRequest.SiteResolver Processor. Located under <httpRequestBegin>
- Then it tries to resolve site using host name. By default Sitecore loads all Site information using Sitecore.Sites.ConfigSiteProvider which loads all the sites defined under <sites> node.
- That’s it!
Sounds good?! For simplicity I’ve removed lot of other things like Firewall, Load Balancer etc. And from Sitecore side before your page gets served lot of interesting thing happens in between. Like Item resolution, render Layout etc. May be sometime later. Will write on those topics. Or why don’t you write it? What you don’t have blog? Please create one. Read this Every developer should have blog!
Good To Read:
Thanks to Gliffy folks for proving Free Gliffy Chrome App!