locked
set Thread.CurrentThread.CurrentCulture in httpmodule, why not get the correct value in page_load in aspx? RRS feed

  • Question

  • User-2021386652 posted

    In order to set localization. I set Thread.CurrentThread.CurrentCulture in httpmodule

    private

    void Application_BeginRequest(object sender, EventArgs

    e)

    {

    System.Threading.

    Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("zh-CN"

    );

    System.Threading.

    Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CN"

    );

    }

    but, in aspx page, the page_load event still get the value "en-US" by Thread.CurrentThread.CurrentCulture

    Response.Write(System.Threading.

    Thread

    .CurrentThread.CurrentUICulture.Name);

    Response.Write(System.Threading.

    Thread

    .CurrentThread.CurrentCulture.Name);

     

    what I expect is that the page_load can get "zh-CN" by Thread.CurrentThread.CurrentCulture

    Thanks,

    Joey

    Friday, November 4, 2011 4:56 AM

Answers

  • User-1538470556 posted

    This is because of the page directives "Culture" and "UICulture" set to auto.

    Try to remove these directives from the page and instead set the base culture from the web.config file

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 15, 2011 6:37 AM