asp.net.ph

GlobalizationSection Class

System.Web.Configuration Namespace


.NET Framework version 2.0

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

GlobalizationSection Class Members

Collapse   Constructors

Visibility Constructor Parameters
public GlobalizationSection ( )

Collapse   Properties

Visibility Name Value Type Accessibility
public Culture String [ Get , Set ]
public EnableBestFitResponseEncoding Boolean [ Get , Set ]
public EnableClientBasedCulture Boolean [ Get , Set ]
public FileEncoding Encoding [ Get , Set ]
public RequestEncoding Encoding [ Get , Set ]
public ResourceProviderFactoryType String [ Get , Set ]
public ResponseEncoding Encoding [ Get , Set ]
public ResponseHeaderEncoding Encoding [ Get , Set ]
public UICulture String [ Get , Set ]

Collapse   Methods

Visibility Name Parameters Return Type
protected PostDeserialize ( ) Void
protected PreSerialize ( XmlWriter writer ) Void

Remarks

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

Example

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.

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

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 = 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 = 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 ( );
      }
   }
}
  C# VB

See Also

ASP.NET Configuration   <globalization> Section Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph