Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

GlobalizationSection Class

Defines configuration settings that are used to support the globalization infrastructure of Web applications. This class cannot be inherited.

Namespace: System.Web.Configuration
Assembly: System.Web (in system.web.dll)

public sealed class GlobalizationSection : ConfigurationSection
public final class GlobalizationSection extends ConfigurationSection
public final class GlobalizationSection extends ConfigurationSection
Not applicable.

The GlobalizationSection class provides a way to programmatically access and modify the content of the globalization section of the configuration file.

This example demonstrates how to specify values declaratively for several attributes of the globalization section, which can also be accessed as members of the GlobalizationSection class.

The following configuration file example shows how to specify values declaratively for the globalization section.

<system.web>
  <globalization 
    requestEncoding="utf-8"
    responseEncoding="utf-8"/>
</system.web>

The following code example demonstrates how to use the GlobalizationSection class.

#region Using directives

using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Web;
using System.Web.Configuration;

#endregion

namespace Samples.Aspnet.SystemWebConfiguration
{
  class UsingGlobalizationSection
  {
    static void Main(string[] args)
    {
      try
      {
        // Set the path of the config file.
        string configPath = "";

        // Get the Web application configuration object.
        Configuration config = WebConfigurationManager.OpenWebConfiguration(configPath);

        // Get the section related object.
        GlobalizationSection configSection =
          (GlobalizationSection)config.GetSection("system.web/globalization");

        // Display title and info.
        Console.WriteLine("ASP.NET Configuration Info");
        Console.WriteLine();

        // Display Config details.
        Console.WriteLine("File Path: {0}",
          config.FilePath);
        Console.WriteLine("Section Path: {0}",
          configSection.SectionInformation.Name);

        // Display Culture property.
        Console.WriteLine("Culture: {0}",
          configSection.Culture);
        
        // Set Culture property.
        configSection.Culture = 
          System.Globalization.CultureInfo.CurrentCulture.ToString();
         
        // Display EnableClientBasedCulture property.
        Console.WriteLine("EnableClientBasedCulture: {0}", 
          configSection.EnableClientBasedCulture);

        // Set EnableClientBasedCulture property.
        configSection.EnableClientBasedCulture = false;

        // Display FileEncoding property.
        Console.WriteLine("FileEncoding: {0}", 
          configSection.FileEncoding);

        // Set FileEncoding property.
        configSection.FileEncoding = 
          System.Text.Encoding.UTF8;

        // Display RequestEncoding property.
        Console.WriteLine("RequestEncoding: {0}",
          configSection.RequestEncoding);

        // Set RequestEncoding property.
        configSection.RequestEncoding = 
          System.Text.Encoding.UTF8;

        // Display ResponseEncoding property.
        Console.WriteLine("ResponseEncoding: {0}",
          configSection.ResponseEncoding);

        // Set ResponseEncoding property.
        configSection.ResponseEncoding = 
          System.Text.Encoding.UTF8;

        // Display ResponseHeaderEncoding property.
        Console.WriteLine("ResponseHeaderEncoding: {0}", 
          configSection.ResponseHeaderEncoding);

        // Set ResponseHeaderEncoding property.
        configSection.ResponseHeaderEncoding = 
          System.Text.Encoding.UTF8;

        // Display UICulture property.
        Console.WriteLine("UICulture: {0}",
          configSection.UICulture);

        // Set UICulture property.
         configSection.UICulture = 
           System.Globalization.CultureInfo.CurrentUICulture.ToString();

        // Update if not locked.
        if (!configSection.SectionInformation.IsLocked)
        {
          config.Save();
          Console.WriteLine("** Configuration updated.");
        }
        else
        {
          Console.WriteLine("** Could not update, section is locked.");
        }
      }

      catch (Exception e)
      {
        // Unknown error.
        Console.WriteLine(e.ToString());
      }

      // Display and wait
      Console.ReadLine();
    }
  }
}

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.