Declaring Culture Globally in ASP.NET


ASP.NET enables you to easily define the culture that is used either by your entire ASP.NET application or by a specific page within your Web application, using what are termed server-side culture declarations. You can specify the culture for any of your ASP.NET applications by means of the appropriate configuration files. In the default install of ASP.NET, no culture is specified, as is evident when you look at the global web.config.comments file found in the ASP.NET 2.0’s CONFIG folder (C:\WINDOWS\Microsoft.NET\ Framework\v2.0.50727\CONFIG). This file contains a <globalization> section of the configuration document, presented here:

  <globalization requestEncoding="utf-8" responseEncoding="utf-8" fileEncoding=""  culture="" uiCulture="" enableClientBasedCulture="false"  responseHeaderEncoding="utf-8" resourceProviderFactoryType=""  enableBestFitResponseEncoding="false" /> 

Note the two attributes represented in bold - culture and uiCulture. The culture attribute enables you to define the culture to use for processing incoming requests, whereas the uiCulture attribute enables you define the default culture needed to process any resource files in the application (use of these attributes is covered later in the chapter).

As you look at the configuration declaration in the preceding code block, you can see that nothing is specified for the culture settings. One option you have when specifying a culture on the server is to define this culture in the web.config.comments file. This causes every ASP.NET 2.0 application on this server to adopt this particular culture setting. The other option is to specify these settings in the web.config file of the application, as illustrated here:

  <configuration>    <system.web>       <globalization culture="ru-RU" uiCulture="ru-RU" />    </system.web> </configuration> 

In this case, the culture established for just this ASP.NET application is the Russian language in the country of Russia. In addition to setting the culture at either the server-wide or the application-wide level, another option is to set the culture at the page level. This is illustrated in the following example:

  <%@ Page Language="VB" UICulture="ru-RU" Culture="ru-RU" %> 

This example specifies that the Russian language and culture settings are used for everything on the page. You can see this in action by using this @Page directive and a simple calendar control on the page. Figure 6-5 shows the output.

image from book
Figure 6-5




Professional VB 2005 with. NET 3. 0
Professional VB 2005 with .NET 3.0 (Programmer to Programmer)
ISBN: 0470124709
EAN: 2147483647
Year: 2004
Pages: 267

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net