Home > Asp.net > Read/Acess globalization section of system.web from web.config

Read/Acess globalization section of system.web from web.config


To read web.config, and find any section there are number of solutions available, one such method to access globalization section which is under system.web of web.config is as follows:

In web.config i have

<globalization uiCulture=”nl-NL”   />

Now to read the uiculture in codebehind file in asp.net

string uicul = ((System.Web.Configuration.GlobalizationSection)(System.Configuration.ConfigurationSettings.GetConfig(“system.web/globalization”))).UICulture;

Lets say for example i have to display date  according to culture set in web.confg so:

public object GetDateCulture(object date)
{
string uicul = ((System.Web.Configuration.GlobalizationSection)(System.Configuration.ConfigurationSettings.GetConfig(“system.web/globalization”))).UICulture;
System.IFormatProvider format = new System.Globalization.CultureInfo(uicul, true);
date = Convert.ToDateTime(date).ToString(“dd MMM yyyy”, format);
return date;
}

Ouput will be:

if culture is english : 22 May 2009

if culture is dutch : 22 Mai 2009


Advertisements
  1. Tati
    March 11, 2011 at 10:58 pm

    Thanks for your help. I wonder why when you put that value in web.config, Thread.CurrentThread.CurrentUICulture or CurrentCulture does not pick it up from Web.config.

  2. Pankaj
    June 4, 2013 at 9:26 am

    ((System.Web.Configuration.GlobalizationSection)(System.Configuration.ConfigurationManager.GetSection(“system.web/globalization”))).Culture;
    should be used in place of GetConfig();

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: