Multi Language problem RRS feed

  • Question

  • User-459769286 posted

    Hi everyone,

    I want to add a multi language dropdown list for sevral pages and i followed the this tutorial http://www.mikesdotnetting.com/Article/183/Globalization-And-Localization-With-Razor-Web-Pages

    Default language is english. I have two language choosing links on the top position of the website (french / english). When I choose french, it switches to the french version of the page. But when I go further in the navigation it switches back to the english page. How can I manage to stay on the french pages?

    I don't know where i should put 

            Culture = UICulture = Request["lang"];
            Culture = UICulture = "en-GB";

    i didn't put in _pageStart, because then i click another button in the navigation menu, page will be displayed in english... 


    Tuesday, August 28, 2012 5:54 AM

All replies

  • User-1415595675 posted


    I have the same problem as the OP. 

    I followed the same great article by Mikesdotnetting.com (thanks Mike!) about globalization with razor web pages and though it works like a charm, the language selection does not persist across different pages and user requests.  

    Could someone give me some pointers or code example on how to pass the language selection (the post method currently sits in my _SiteLayout.cshtml) to a session or a cookie, hence make other pages read the session or cookie and inherit its value (instead of switching back to default culture) 

    Thanks in advance! 

    Wednesday, May 15, 2013 3:00 AM
  • User-1415595675 posted

    I am going to answer myself on this one, as i figured out the cookie method! 

    so on your _PageLayout.cshtml you can do the following: 

        Layout = "~/_SiteLayout.cshtml";
        if (!Request["lang"].IsEmpty())
            //this runs when you post the language change so I save the language to a cookie named lang
            Response.Cookies["lang"].Value = Request["lang"];
            Culture = UICulture = Request["lang"];
        else if (Response.Cookies.Get("lang").Value != null)
            //this will only run if there was no post request with lang and if there is a cookie lang set
            Culture = UICulture = Response.Cookies.Get("lang").Value;
    I know it's pretty simple for the gurus out there, but I picked up asp.net about a week ago and I was stuck on this for two days :P 
    Hope it helps someone!
    Thursday, May 16, 2013 1:51 AM