Wednesday, May 4, 2011

Setting a variation label to be the default entry to a publishing Site

 ·         Directly edit the VariationsRootLanding.ascx file.
This is the quickest way to edit the logic. Edit the logic in the VariationsRootLanding.ascx file as needed, on the front-end Web server file system.
·         Navigate to the path “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\CONTROLTEMPLATES” here you will find the VariationsRootLanding.ascx file open the file and to edit.
To modify the root landing logic to detect when a functioning Web site is present
1.       In the GetRedirectUrl() section, find this line of code.
return (string.IsNullOrEmpty(matchedUrl) ? sourceLabelUrl : matchedUrl);
2.       Replace the line of code in Step 1 with the following code.
That I'm redirecting to my source Variation label with the index of "0".

       #region Redirecting to a custom variation
       // Customization for handling matchedUrl not valid.
       // (For example, a content deployed target site collection,
       // without source hierarchy.)
       matchedUrl = (string.IsNullOrEmpty(matchedUrl) ? sourceLabelUrl : matchedUrl);
       using (SPSite site = new SPSite(matchedUrl))
       using (SPWeb web = site.OpenWeb())
            // If matchedUrl is the same as the URL of the Web
            // that you just opened, then matchedUrl is valid.
            if (string.Compare(matchedUrl, web.Url, StringComparison.OrdinalIgnoreCase) == 0 && web.DoesUserHavePermissions(SPBasePermissions.Open))
                //Target URL is valid; return it.
                //return matchedUrl;
                SPSite Site = new SPSite(http://win-1eppeqik472/sites/Publishing);
                SPWeb Web = Site.RootWeb;
                Guid varListId = new Guid(Web.AllProperties["_VarLabelsListId"] as string);
                SPList varList = Web.Lists[varListId];
                String URL = varList.Items[0].Web.Url;
                URL += "/" + varList.Items[0].Name + "/Pages/default.aspx";
                return URL;
                 //Target URL was NOT valid; the variation label is missing.
                 //Perform logic here to redirect the user appropriately.
                 //If nothing is done here, then this function returns null
                 //and the landing behavior reverts to the
                 //VariationsRootLandingRunTime control.
                 //This control displays a simple error message that
                 //indicates that it could not find an appropriate subsite to
                 //redirect to.
                 return "http://win-1eppeqik472/sites/Publishing/Arabic/Pages/default.aspx";

No comments:

Post a Comment