Pages

Thursday, February 10, 2011

SharePoint Variations – How they did Variation Landing Page – Part 1

When we talk about SharePoint Variation, we usually get thought of making sites multilingual. Yes that’s correct.
I will not be describing all in depth of Variations like how Variations can be set up and about installing language packs, there are many well articles which describes this in details
What I am really interested in putting forward is , how SharePoint Variation Redirections happens?
it all starts from creating Variations hierarchies
when all Variations labels are set up and one presses create site hierarchies link then SharePoint creates a timer job called as Variation Create Site Hierarchies job (SharePoint 2010) , what this job internally does is          ( I tried using reflector here for internals)  it creates variation sites in different languages referring to web temp files in 14 hive (according to language installed) and also creates a page called as VariationRoot.aspx
now this VariationRoot.aspx page is set as welcome page for the site , idea here is to expose this page to all users and do some action as soon as user visits this page and redirect them to actual variation site url , doing this we never practically see or visit VariationRoot.aspx but directly gets redirected to Variation Site
What VariatonRoot.aspx has?
Well, If we see what VariatonRoot.aspx has then I figured out that this page is provisioned by using page layout called as VariationRootPageLayout.aspx
What VariationRootPageLayout has?
Now into more deeper dive.. This page layout contains a use control called as VariationRootLanding.ascx
Actual process of redirection in done in this control
I will explain how
 This is generally a browser culture identification approach . When request comes to this page then user control tries to get the culture preferences of user’s browser and tries to redirect user to nearest available variation site




Code:
Control maintains two Dictionary objects on each page load of landing page
Dictionary<string, string> cultureCodeToUrlMapping = new Dictionary<string, string>();

Dictionary<string, string> cultureCodeStrippedToUrlMapping = new Dictionary<string, string>();
First dictionary object contains the actual language culture code as key and variation site url as value
                                                Key                        Value  
Example:                               en-US ,           http://www.test.com/English
                                             fi-FI,              http://www.test.com/Finnish
                                             de-DE ,           http://www.test.com/German
so this is primary criteria on which just a simple check is done on requesting browser’s culture and searched in dictionary object

Second dictionary object contains stripped culture code and url mapping

Example:                                en ,               http://www.test.com/English
                                              fi ,                http://www.test.com/Finnish
                                              de ,               http://www.test.com/German

Why this is needed now?
Suppose I have variation site with culture en-US and user’s browser requesting culture as en-IN then what to do in this case?
If exact key is not found in first dictionary object then SharePoint searches in second dictionary object with stripped  key to redirect users to possibly closest culture variation site
so in this case users with browser culture en-IN will be redirected to en-US variation site
so basically this is the concept used in OOB VariationRootLanding user control , in next part I will write something on how we can customize this or create our custom VariationLandingPage

No comments:

Post a Comment