Localizing the SharePoint login page   

 

The login page is localized, however due to the way login pages are set in asp.net it will only use the language of the web site in the root of your SharePoint site (rootweb of the top site collection).

When you have to log in to a SharePoint site using FBA you are redirected to "/_layouts/login.aspx". The url can be set in the web.config but the problem is that you can only have one login page per web application. This is usually fine as long as all sites in the web application use the same language.

As the login page runs under the scope of the root web it will use its language and the language of any sub sites will not be considered at all. This problem applies to all application pages that are executed in the context of a root site.

To work around this you can override the InitializeCulture method of the login page. In the example below I'm using the ReturnUrl parameter to establish the language of the original request.

 Code Snippet

protected override void  InitializeCulture()    
{        
    try
    {                
        string originalRequest = this.Request.QueryString["ReturnUrl"].ToString();

        System.Uri u = new System.Uri(SPContext.Current.Site.Url);

        // TODO: Improve the way we create the site collection url
        originalRequest = "http://" + u.Host + originalRequest;

        Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(delegate()
        {
            // This is the original site collection requested
            using (Microsoft.SharePoint.SPSite site = new Microsoft.SharePoint.SPSite(originalRequest))
            { 
                using (Microsoft.SharePoint.SPWeb web = site.RootWeb)
                { 
                    System.Threading.Thread.CurrentThread.CurrentUICulture = web.Locale;
                }                
            }
        });
    }
    catch { }
    base.InitializeCulture();
}

You can embed this method in the login page inside a server script tag (<script runat="server" />) or you can put it in the code behind class if you are extending the login page.

Notice that the script is considering the root web of the original site collection. To be correct it should consider the original web site instead. I will leave it up to you to improve the code in case webs in the site collections are using different languages.

Published  on  9/15/2009  by  xsolon
0  Comments  |  Trackback Url  | 0  Links to this post | Bookmark this post with:          
Tags: | Categories:
Technorati Tags:
 

Links to this post

Comments

Title:
Receieve Notification:
Website:
Email:
Comments:

CAPTCHA Image Validation