Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6073267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:15:09+00:00 2026-05-23T10:15:09+00:00

I have an ASP.NET MVC site that it’s in two languages using Resources. To

  • 0

I have an ASP.NET MVC site that it’s in two languages using Resources. To allow the server to present the site in the apropiate language (depending on the one that’s configured in the user’s browser) I put the following in my web.config:

<globalization culture="es-es" uiCulture="auto" />

How can I add a link to change the uiCulture? I want to store the selection in a cookie and if it’s not present, then fall back to the browser configuration… Is it possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:15:10+00:00Added an answer on May 23, 2026 at 10:15 am

    You may take a look at the following guide. It uses Session to store the current user language preference but the code could be very easily tweaked in order to use a cookie. The idea is that you will have a controller action:

    public ActionResult ChangeCulture(string lang, string returnUrl)
    {
        var langCookie = new HttpCookie("lang", lang)
        {
            HttpOnly = true
        };
        Response.AppendCookie(langCookie);
        return Redirect(returnUrl);
    }
    

    and then in Global.asax you could subscribe for the Application_AcquireRequestState event in order to set the current thread culture based on the value of the cookie:

    protected void Application_AcquireRequestState(object sender, EventArgs e)
    {
        var langCookie = HttpContext.Current.Request.Cookies["lang"];
        if (langCookie != null)
        {
            var ci = new CultureInfo(langCookie.Value);
            //Checking first if there is no value in session 
            //and set default language 
            //this can happen for first user's request
            if (ci == null)
            {
                //Sets default culture to english invariant
                string langName = "en";
    
                //Try to get values from Accept lang HTTP header
                if (HttpContext.Current.Request.UserLanguages != null && HttpContext.Current.Request.UserLanguages.Length != 0)
                {
                    //Gets accepted list 
                    langName = HttpContext.Current.Request.UserLanguages[0].Substring(0, 2);
                }
    
                langCookie = new HttpCookie("lang", langName)
                {
                    HttpOnly = true
                };
    
    
                HttpContext.Current.Response.AppendCookie(langCookie);
            }
    
            //Finally setting culture for each request
            Thread.CurrentThread.CurrentUICulture = ci;
            Thread.CurrentThread.CurrentCulture = ci;
    
            //The line below creates issue when using default culture values for other
            //cultures for ex: NumericSepratore.
            //Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ci.Name);
        }
    }
    

    Now this being said using cookies and session to store current language is not SEO friendly. What I prefer doing when I need a localized application is to use a special route which will contain the language:

    routes.MapRoute(
        "Default",
        "{lang}/{controller}/{action}/{id}",
        new 
        { 
            lang = "en-US",   
            controller = "Home", 
            action = "Index", 
            id = UrlParameter.Optional 
        }
    );
    

    and then prefix all my urls with the language. This provides unique urls for different languages so that robots can properly index all content. Now all that’s left is to modify the Application_AcquireRequestState method so that it uses the lang token of the url and based on its value set the proper Thread.CurrentThread.CurrentUICulture and Thread.CurrentThread.CurrentCulture.

    And now when you wanted to change the language you would simply generate the proper link:

    @Html.ActionLink("Page index en français", "index", new { lang = "fr-FR" })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ASP.NET MVC site that is locked down using Forms Authentication. The
I am building an Asp.net MVC site where I have a fast dedicated server
I've been developing a site using ASP.NET MVC, and have decided to use the
I am currently creating an e-commerce site using C# ASP.NET MVC and have just
I have an ASP.NET MVC (Beta 1) website that I'm using themes with. When
I have asp.net mvc intranet site that is deployed to IIS6. Site is used
I have an ASP.Net MVC site that generates a Microsoft Excel 2003 XML formatted
I have a asp.net mvc site that references a couple of libraries. Recently I
I have an ASP.NET MVC site that uses both Microsoft Ajax [ Ajax.BeginForm() ]
Ok, so this is my dilemma... I have an ASP.NET MVC site that is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.