GlobalizationSection 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
定义用于支持 Web 应用程序的全球化基础结构的配置设置。 此类不能被继承。
public ref class GlobalizationSection sealed : System::Configuration::ConfigurationSection
public sealed class GlobalizationSection : System.Configuration.ConfigurationSection
type GlobalizationSection = class
inherit ConfigurationSection
Public NotInheritable Class GlobalizationSection
Inherits ConfigurationSection
- 继承
示例
此示例演示如何以声明方式为节的 globalization
多个属性指定值,这些属性也可以作为类的成员 GlobalizationSection 进行访问。
以下配置文件示例演示如何以声明方式为 globalization
节指定值。
<system.web>
<globalization
requestEncoding="utf-8"
responseEncoding="utf-8"/>
</system.web>
下面的代码示例演示如何使用 GlobalizationSection 类。
#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();
}
}
}
Imports System.Collections.Generic
Imports System.Text
Imports System.Configuration
Imports System.Web
Imports System.Web.Configuration
Namespace Samples.Aspnet.SystemWebConfiguration
Class UsingGlobalizationSection
Public Shared Sub Main()
Try
' Set the path of the config file.
Dim configPath As String = ""
' Get the Web application configuration object.
Dim config As System.Configuration.Configuration = _
WebConfigurationManager.OpenWebConfiguration(configPath)
' Get the section related object.
Dim configSection As System.Web.Configuration.GlobalizationSection = _
CType(config.GetSection("system.web/globalization"), _
System.Web.Configuration.GlobalizationSection)
' 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 Not configSection.SectionInformation.IsLocked Then
config.Save()
Console.WriteLine("** Configuration updated.")
Else
Console.WriteLine("** Could not update, section is locked.")
End If
Catch e As Exception
' Unknown error.
Console.WriteLine(e.ToString())
End Try
' Display and wait
Console.ReadLine()
End Sub
End Class
End Namespace
注解
类 GlobalizationSection 提供了一种以编程方式访问和修改配置文件部分内容 globalization
的方法。
构造函数
GlobalizationSection() |
使用默认设置初始化 GlobalizationSection 类的新实例。 |