MOSS 2007 WCM Development Part 2 – Customize Variation Root Landing Logic

February 9, 2007 at 1:17 am 15 comments

If you are thinking about using the Variation feature of SharePoint 2007, you will likely have to customize the variation root landing logic of SharePoint. For instance, you give your users web site language preferences and have them redirected to their language of choice after they authenticated with your SharePoint web site.

There are a few ways to customize the variation landing logic as documented by the SDK. Let me illustrate using an example.

Scenario:

  1. SharePoint is configured to use variations for different languages
  2. SharePoint is configured to use Forms Authentication
  3. User Profile is stored in a custom SQL database
  4. User Profile has language preference corresponding to the variations defined for the site
  5. SharePoint will redirect user to the language of choice once they have authenticated

How Variation works:

When SharePoint is setup to use Variations, the root site collection is no longer used to store pages. Instead, you will have sub sites under the web root representing your variations. For example, I have English and French variations, when I browse to my SharePoint site, it will redirect me to either the English or the French sub site. The root welcome page is configured by SharePoint (upon creation of variation labels and site structures) to point to a file called VariationRoot.aspx. This file contains a user control VariationsRootLanding.ascx, which has the code that redirects.

VariationRoot.aspx

The default behavior of the VariationsRootLanding.ascx is to detect the language setting of the client, and try to match it with one of the variation labels. If no matching variation label is found, it will redirect the user to the source variation label. For this example, I set up two variation labels: en-CA and fr-CA (en-CA being my source variation label).

Variation Labels

Notice that the labels are setup to use the culture-region format. If you don’t follow this format, the variation logic will not be able to match the client language properly.

How to customize:

So how about giving users a language preference to your web site regardless of their regional setting? A practical example would be:

  • a user likes to consume the French content
  • He/she logs in to the web site via a public computer that has English as the regional setting
  • We would like to redirect the user to their language preference regardless of what the regional setting the public computer has.

The easiest way is to modify the VariationsRootLanding.ascx file. This user control is actually located in the file system. The path is:

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES\VariationsRootLanding.ascx

This user control does not have any user interface. It is just server side code to redirect a user. The method that we will modify is GetRedirectTargetUrl().

GetRedirectTargetUrl

This code does returns the closest variation label URL based on the client’s regional setting. We still want to keep this code becacuse we need this for anonymous users (we cannot retrieve language preference for users who have not authenticated.) So to modify this, we will add our code around it.

Here is what I considered:

  1. Ensure we are using Forms Authentication
  2. Ensure the user is authenticated
  3. Retrieve the language preference for the currently logged in user
  4. Set our redirect Url by inserting a variation label

Here is a highlight of the modification:

GetRedirectTargetUrlModified

Of course you have to add the required namespaces at the top of the user control. Feel free to modify it and test it out in your own environment.

Advertisements

Entry filed under: MOSS 2007.

How to remove recent projects from Visual Studio Start Page ASP.NET Role-Based Security

15 Comments Add your own

  • […] post qui!! Posted: martedì 10 aprile 2007 18.34 by romeo Filed under: […]

    Reply
  • 2. Michal  |  May 11, 2007 at 9:57 am

    How would I remove the “Francais” from the breadcrumb? It appears automatically.

    Reply
  • 3. aspnetcoe  |  May 11, 2007 at 10:17 am

    Hi Michal, please take a look at one of my previous posts and see if it can help you to remove variation labels from the breadcrumb: https://aspnetcoe.wordpress.com/2006/09/28/

    Reply
  • 4. Idetrorce  |  December 15, 2007 at 5:02 am

    very interesting, but I don’t agree with you
    Idetrorce

    Reply
  • 5. aspnetcoe  |  December 17, 2007 at 11:00 am

    Hi Idetrorce, thanks for your comments. Could you kindly elaborate? I am sure your ideas will benefit me and anyone else who might be reading this posting.

    Reply
  • […] knowledge is out there, know the […]

    Reply
  • 7. Alex  |  September 11, 2008 at 9:25 am

    Hi,
    i have a security problem with my variationrootlandig.ascx.
    I have the following code:
    string[] browserLanguages = Page.Request.UserLanguages;
    if (null != browserLanguages)
    {
    foreach (string value in browserLanguages)
    {
    if (value.Contains(”fr-CH”) || value.Contains(”it-CH”))
    {
    string[] segments = Page.Request.Url.Segments;
    string protocol = String.Empty;
    if (Page.Request.IsSecureConnection)
    {
    protocol = “https://”;
    }
    else
    {
    protocol = “http://”;
    }
    protocol += Page.Request.Url.Host;
    int i = 0;
    while (segments.Length > i + 2)
    {
    protocol += segments[i];
    i++;
    }
    matchedUrl = protocol + “CH/Pages/”;
    return matchedUrl;

    Everything works fine, when the user is authenticated in MOSS. However anonymous users (publishing sites) tries to access the page, he receives an access denied error message. Do you know how I can handle this problem. Even anonymous users should redirect to the CH variation site.

    When I return a static Url like:
    return matchedUrl = “http://moss/pages/CH/default.aspx” everythin works fine. Why?

    Thanks in advanced.

    Reply
    • 8. Otto  |  January 14, 2010 at 8:25 am

      Hi Alex,
      did you solved the problem.
      My problem is quite the same:
      With Form authenticated, when the anonymous user try to open a variation (no source) site, it is always redirected to the login page.
      The sites have anonymous access.

      With Active Directory, when the anonymous user try to open a variation (no source) site, the AD user is sing in authomatically.

      Any idea why is this happening?

      Thanks in advance.

      Reply
  • 9. net2tech  |  June 16, 2009 at 1:14 pm

    Can I use these variations to go to an ASP.NET site from SharePoint?

    Essentially, can I make an ASP.NET site I have as a subsite of SharePoint.

    Reply
  • […] BDC Audiences Profiles Content Management and here  and here BI Workflow Info mgmt Variations Records Management Infopath Also run through: Custom field control which displays the video […]

    Reply
  • 12. weeklyvolcano.com  |  March 22, 2013 at 1:02 am

    I am regular reader, how are you everybody? This paragraph posted at this web site is genuinely nice.

    Reply
  • 13. hotmail email directory  |  April 23, 2013 at 11:31 am

    I am actually grateful to the holder of this web
    page who has shared this fantastic article at at this place.

    Reply
  • 14. coupons for video games  |  May 22, 2013 at 1:46 pm

    Before you start buying games that you can recruit and upgrade
    creatures to assist you in your battles against the many minions of the White Witch.
    These, however, Pokmon with Pickup can also gain an item thrown at it using Fling.

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


February 2007
M T W T F S S
« Sep   Apr »
 1234
567891011
12131415161718
19202122232425
262728  

Feeds

Blog Stats

  • 116,073 hits

%d bloggers like this: