Microsoft KB Archive/306162

= HOW TO: Set Current Culture Programmatically in an ASP.NET Application =

Article ID: 306162

Article Last Modified on 10/29/2007

-

APPLIES TO


 * Microsoft ASP.NET 1.1
 * Microsoft ASP.NET 1.0

-



This article was previously published under Q306162



IN THIS TASK

 * SUMMARY
 * Application Level
 * Page Level
 * Thread Level
 * REFERENCES



SUMMARY
This step-by-step article describes how to change the current culture and current UI culture in an ASP.NET application. In the .NET Framework, the CultureInfo class from the System.Globalization namespace provides culture-specific information such as the associated language, country/region, calendar, and cultural conventions. The CurrentCulture property represents the culture that the current thread uses. The CurrentUICulture property represents the current culture that Resource Manager uses to look up culture-specific resources at run time. There are three ways to set the Culture information in an ASP.NET application, Application Level, Page Level, and Thread Level.

back to the top

Application Level
Specify Application Level Culture information in the Web.config file. To do this, follow these steps:  Start Notepad (or any other text editor).  Paste the following code in Notepad:     Save the text file as Web.config in the root folder of your Web server. For example, C:\Inetpub\wwwroot\Web.config.  Start another instance of Notepad. Paste the following code in Notepad: <%@Page Language=&quot;C#&quot; %> <% @Import Namespace=&quot;System.Globalization&quot; %> public void Page_Load {        Response.Write (&quot;Current Culture is &quot; + CultureInfo.CurrentCulture.EnglishName); }

 Save this text file as Application.aspx in the root folder of your Web server.</li> Start Internet Explorer, and then open Application.aspx.</li></ol>

back to the top

Page Level
The Page Level Culture-specific information settings override the Application Level Culture-specific information settings. Specify Page Level Culture information by using the @Page directive. To do this, follow these steps: <ol> Follow steps 1, 2, and 3 of the &quot;Application Level&quot; section to create the Web.config file.</li>  Start another instance of Notepad. Paste the following code in Notepad: <%@Page Culture=&quot;fr-FR&quot; Language=&quot;C#&quot; %> <% @Import Namespace=&quot;System.Globalization&quot; %> public void Page_Load {        Response.Write (&quot;Current Culture is &quot; + CultureInfo.CurrentCulture.EnglishName); }

</li> Save this text file as Page.aspx in the root folder of your Web server.</li> Start Internet Explorer, and then open Page.aspx. Note that the Current Culture setting is French, although Japanese is specified as the current culture in the Web.config file.</li></ol>

back to the top

Thread Level
The Thread Level Culture-specific information settings override the Page Level Culture-specific information settings. Specify the Thread Level Culture-specific information by setting the CurrentCulture property or the CurrentUICulture property of the current thread. To do this, follow these steps: <ol> Follow the steps 1, 2, and 3 of the &quot;Application Level&quot; section to create the Web.config file.</li>  Start another instance of Notepad. Paste the following code in Notepad: <% @Page Culture=&quot;fr-FR&quot; Language=&quot;C#&quot; %> <% @Import Namespace=&quot;System.Globalization&quot; %> <% @Import Namespace=&quot;System.Threading&quot; %> public void Page_Load {    // Display the Current Culture Response.Write(&quot;Current Culture is &quot; + Thread.CurrentThread.CurrentCulture.EnglishName + &quot; &quot;); // Modify the Current Culture Thread.CurrentThread.CurrentCulture = new CultureInfo(&quot;de-DE&quot;); Response.Write(&quot;Changing Culture to &quot; + Thread.CurrentThread.CurrentCulture.EnglishName + &quot; &quot;);

}

</li> Save this text file as Thread.aspx in the root folder of your Web server.</li> Start Internet Explorer, and then open Thread.aspx. Note that the Current Culture setting is German, although French is specified at the page level and Japanese is specified in the Web.config file.</li></ol>

back to the top

<div class="references_section">