Search code examples
asp.net-mvc-3sessionglobalizationhttpcontextcultureinfo

Application_AcquireRequestState() fires multiple times


I use this following method in mvc3 application:

protected void Application_AcquireRequestState(object sender, EventArgs e)
        {
          if (HttpContext.Current.Session != null)
            {
                CultureInfo ci = (CultureInfo)this.Session["Culture"];

                if (ci == null)
                {
                    string langName = "az";
                    ci = new CultureInfo(langName);
                    this.Session["Culture"] = ci;
                }

                Thread.CurrentThread.CurrentUICulture = ci;
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ci.Name);
            }
        }

Why is this method called many times?

And when site opens in new browser in other PC, site resources not found.


Solution

  • Does your page have multiple elements (images, scripts, etc.) resulting in multiple HTTP Get requests? If so, this will fire once for each.