简体   繁体   中英

ADFS Login Page Localization - ASP.NET: I can't seem to be able to change language of the page dynamically

In my project we're using the default ADFS login page to log in to ADFS as single sign on. The page itself takes loads of parameters but I am unable to get any of them from the request. I've created an override function for initialize culture as follows:

protected override void InitializeCulture()
{
    string languageId = Request["lang"];

    if (languageId != null)
    {
        Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(languageId);
        Thread.CurrentThread.CurrentUICulture = new CultureInfo(languageId);
    }       

    base.InitializeCulture();
}

The idea was to have a flag that is a link, which would add something I could catch from the initialize culture method from the request.

Now setting the culture by hand (as in, skipping the Request reading part) works just fine and I am able to change the language and culture of my page. However I am unable to get anything from the request. This includes any predefined parameters in the original get URL.

I am also unable to store anything to session and I am assuming its because of the way the login page is created.

Has anyone been able to localize their ADFS login page dynamically? If so, any pointers would be appreciated.

You need to look at Request.UserLanguages to get the culture from the request. Not sure if Request["lang"] works consistently.

I use some generic code to set the locale which looks like this:

    public static void SetUserLocale(string currencySymbol, bool setUiCulture)
    {
        HttpRequest Request = HttpContext.Current.Request;
        if (Request.UserLanguages == null)
            return;

        string Lang = Request.UserLanguages[0];
        if (Lang != null)
        {
            if (Lang.Length < 3)
                Lang = Lang + "-" + Lang.ToUpper();
            try
            {
                CultureInfo Culture = new CultureInfo(Lang);
                if (currencySymbol != null && currencySymbol != "")
                    Culture.NumberFormat.CurrencySymbol = currencySymbol;

                Thread.CurrentThread.CurrentCulture = Culture;

                if (setUiCulture)
                    Thread.CurrentThread.CurrentUICulture = Culture;
            }
            catch
            { /// avoid invalid language selection bombing }
        }
    }

I tend to call this not in a page but in Application_BeginRequest so it's global.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM