Archive for February, 2007

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

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.

February 9, 2007 at 1:17 am 21 comments

How to remove recent projects from Visual Studio Start Page

(This is not a new trick but just in case you are looking for it.)

Visual Studio Recent Project List

Sometimes we create projects just for experimentation and then soon after we are done with the experimentation, we delete the project from the file system in order not to clutter up our working environment. But what about Visual Studio? The Start page of Visual Studio has a list of recent projects and it is meant for a convenient feature. But for the experimental projects that no longer exist, that list does not really reflect the reality.

To remove the projects from the list, follow these steps:

  1. Close Visual Studio if it is running.
  2. Start the Registry Editor (run regedit).
    Registry Editor
  3. Navigate to this registry key:
    HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0\ProjectMRUList
    Registry Editor 2
  4. Then delete the key that has the project you do not want to keep in the list.

A little note to keep in mind is that the list only lists consecutive items starting File1. So if in the above list I deleted File6, then only projects corresponding to File1 to File5 will be displayed in the recent project list. File7 and above will not be displayed. If in case you like File7 and above to be displayed, you will need to rename one of the keys so that they form a consecutive numbered list.

kick it on DotNetKicks.com

February 6, 2007 at 12:00 am 80 comments


February 2007
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728  

Feeds

Blog Stats

  • 118,537 hits