Click to Rate and Give Feedback
MSDN
MSDN Library
Office Development
SDK Documentation
General Reference
 How to: Customize the Variation Roo...

  Switch on low bandwidth view
Community Content
In this section
Statistics Annotations (0)
How to: Customize the Variation Root Landing Logic

When you provision a site collection in Microsoft Office SharePoint Server 2007 and configure variations, Office SharePoint Server 2007 does the following:

  • Creates a page in the variation home site named VariationRoot using the VariationRootPageLayout.aspx page layout file in the Master Page and Page Layouts Gallery.

  • Replaces the default Welcome page of the Variation home site with the VariationRoot page.

If you browse to the Variation home site, Office SharePoint Server 2007 looks up the WelcomePage property of the site and runs the VariationRoot page. Because that page is based on VariationRootPageLayout.aspx, it runs the page layout file. The VariationRootPageLayout page layout contains a reference to a file called VariationsRootLanding.ascx and one user control that is defined in the VariationsRootLanding.ascx file. The Page Layout executes the logic in the VariationsRootLanding.ascx file and redirects the user to a Variation site.

The default logic used in the VariationsRootLanding.ascx file is to redirect the user to the Variation site that matches the browser's accept lang, or array of language codes in which the current document is available. The VariationsRootLanding.ascx file is defined in the path \<Program Files>\Common Files\Microsoft Shared Debug\Web Server Extensions\12\Template\ControlTemplates.

If you want the default Variation root landing page logic to redirect the user to a Variation site that is not based on the accept lang, you can do this in one of three ways. Each option has its own advantages and disadvantages, and you should consider them carefully before deciding which approach to use.

  • Directly edit the VariationsRootLanding.ascx file.

    This is the quickest way to edit the logic. Simply edit the logic in the VariationsRootLanding.ascx file directly as needed on the front-end Web server file system.

    NoteNote:

    You must update the VariationsRootLanding.ascx file on each of the front-end Web server computers. All site collections in the server farm are tied to the custom Variation root landing logic that you specify.

  • Copy the contents from the VariationsRootLanding.ascx file into the Page Layout in the Master Page and Page Layouts Gallery.

    For details about implementing this approach, see the first procedure, To copy the contents from the VariationsRootLanding.ascx file into the Page Layout. Like the previous approach, this approach also provides easy and rapid customization through direct editing, with no DLL compilation and deployment issues. In addition, because each site collection uses its own set of page layouts, this approach allows customization of variation root landing logic on a site collection level. To complete this process, you also must update the web.config file on each of the front-end Web server computers.

    CautionCaution:

    Use caution when setting the AllowCompilation flag on the VariationRootPageLayout.aspx file. Using inline code means that someone could inject malicious code into the page.

  • Create a precompiled assembly.

    For details about implementing this approach, see the second procedure, To create a precompiled assembly. This approach poses no security risk related to opening a Master Page and Page Layouts Gallery item for inline code execution. Like the previous approach, customization is done on a site collection level. However, every time you need to change the variation root landing logic, you must recompile the assembly. This approach therefore offers a less rapid change-test-deploy cycle. You must deploy the assembly on all front-end Web server file system computers.

There is an additional scenario that you can address by modifying code in the VariationsRootLanding.ascx file. If you use a scoped deployment job to deploy a Variations site, and the job does not deploy all Variation labels in the Variation hierarchy from the deployment source, users who ordinarily redirect to those labels receive a 404 error when navigating to the Variation root on the deployment destination. For example, if you have a label in the Variation hierarchy that targets a German locale, and that label is not included in your scoped deployment, browsers set to prefer German locales encounter a 404 error when navigating to the Variation root on the destination computer. The root landing logic, by default, does not check the validity of the redirect URL it chooses.

One way to address this issue is to modify the root landing logic to detect when there is a functioning Web site present at the target redirect URL. To learn how to do this, see the third procedure, To modify the root landing logic to detect when a functioning Web is present.

To copy the contents from the VariationsRootLanding.ascx file into the Page Layout

  1. Copy the code from the VariationsRootLanding.ascx file and embed it in the VariationRootPageLayout.aspx in the Master Page and Page Layouts Gallery.

  2. Make the changes you need.

  3. Remove the reference to the VariationsRootLanding.ascx and its user control from within VariationRootPageLayout.aspx.

  4. To allow inline code execution of VariationRootPageLayout.aspx, modify the web.config file on each Web client as follows.

      <SharePoint>
        <SafeMode ... >
          <!-- marks VariationRootPageLayout.aspx for ASP.NET compilation -->
          <PageParserPath VirtualPath= "/_catalogs/masterpage/VariationRootPageLayout.aspx" 
            CompilationMode="Always"  
            AllowServerSideScript="False"
            AllowUnsafeControls="False" 
            IncludeSubFolders="True"/>
          </PageParserPaths>
        </SafeMode>
      </SharePoint>

To create a precompiled assembly

  1. Copy the code from the VariationsRootLanding.ascx file to create your own control in your own assembly DLL.

  2. Make the necessary changes in the control.

  3. Add a reference to your control to VariationRootPageLayout.aspx in the Master Page and Page Layouts Gallery.

  4. Remove the reference to VariationsRootLanding.ascx and its user control from within VariationRootPageLayout.aspx.

To modify the root landing logic to detect when a functioning Web site is present

  1. Open the VariationsRootLanding.ascx file.

  2. In the GetRedirectUrl() section, find this line of code.

    return (string.IsNullOrEmpty(matchedUrl) ? sourceLabelUrl : matchedUrl);
  3. Replace the line of code in Step 2 with the following code.

    // Customization for handling matchedUrl not valid 
    // (e.g., 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
         // you just opened, then matchedUrl is valid
         if (string.Compare(matchedUrl, web.Url, StringComparison.OrdinalIgnoreCase) == 0 && web.DoesUserHavePermissions(SPBasePermissions.Open))
           {
          //Target URL was valid; return it
            return matchedUrl;
            }
            else
            {
          //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 it could not find an appropriate subsite to 
          //redirect to.
            }
       }

See Also

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
A note on copying the .ascx code to the VariationRootPageLayout.aspx page      BrianGPlano   |   Edit   |   Show History

By default, there is no <%@ Page %> directive in the VariationRootPageLayout.aspx page. So, the default language is VB for the page. The VariationsRootLanding.ascx code is C#. So add the following directive to the top of the page:

<%@ Page language="C#" %>

Tags What's this?: Add a tag
Flag as ContentBug
web.config entry needs correction in the sample above      GyorgyH   |   Edit   |   Show History
The web.config entry is invalid, IncludeSubFolders cannot be specified unless the VirtualPath attribute contains wildcard. Furthemore AllowServerSideScript must be true

<SharePoint>
<SafeMode ... >
<PageParserPaths>
<!-- marks VariationRootPageLayout.aspx for ASP.NET compilation -->
<PageParserPath VirtualPath= "/_catalogs/masterpage/VariationRootPageLayout.aspx"
CompilationMode="Always"
AllowServerSideScript="True"
AllowUnsafeControls="False" />
</PageParserPaths>
</SafeMode>
</SharePoint>
Tags What's this?: Add a tag
Flag as ContentBug
web.config entry assumption needs correction      redmiata   |   Edit   |   Show History
The VirtualPath= "/_catalogs/masterpage/VariationRootPageLayout.aspx" value only works if you are implementing this customization in the VariationRootPageLayout.aspx page in the root site collection. This is not always the case... for all other site collections, you need to update the path to match the location of your custom file, i.e. "/sites/sitecollectionname/_catalogs/masterpage/VariationRootPageLayout.aspx".
Tags What's this?: Add a tag
Flag as ContentBug
Another method for changing the root landing logic...      redmiata   |   Edit   |   Show History

1. Create a copy of VariationsRootLanding.ascx - i.e. 12\Template\ControlTemplates\CustomVariationsRootLanding.ascx or 12\Template\ControlTemplates\Custom\VariationsRootLanding.ascx .

2. Modify the logic in your custom version of VariationsRootLanding.ascx as needed.

3. Update the VariationRootPageLayout.aspx for whatever site collection(s) need to use the custom VariationsRootLanding.ascx to refer to your custom version.

4. Deploy this as a solution with your custom version of VariationsRootLanding.ascx being installed in the 12 hive and the new VariationRootPageLayout.aspx deployed as a feature in the solution.

No need to modify the web.config and open up potential security issues.

Tags What's this?: Add a tag
Flag as ContentBug
The method is actually GetRedirectTargetUrl()      Spencer Harbar ... Thomas Lee   |   Edit   |   Show History
In the latest builds there is no method named GetRedirectUrl, it's GetRedirectTargetUrl()
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker