GlobalizationSection Klass
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Definierar konfigurationsinställningar som används för att stödja globaliseringsinfrastrukturen för webbprogram. Det går inte att ärva den här klassen.
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
- Arv
Exempel
Det här exemplet visar hur du anger värden deklarativt för flera attribut i globalization avsnittet, som också kan nås som medlemmar i GlobalizationSection klassen.
Följande konfigurationsfilexempel visar hur du anger värden deklarativt för globalization avsnittet.
<system.web>
<globalization
requestEncoding="utf-8"
responseEncoding="utf-8"/>
</system.web>
Följande kodexempel visar hur du GlobalizationSection använder klassen.
#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
Kommentarer
Klassen GlobalizationSection ger ett sätt att programmatiskt komma åt och ändra innehållet i globalization avsnittet i konfigurationsfilen.
Konstruktorer
| Name | Description |
|---|---|
| GlobalizationSection() |
Initierar en ny instans av GlobalizationSection klassen med hjälp av standardinställningar. |
Egenskaper
| Name | Description |
|---|---|
| Culture |
Hämtar eller anger ett värde som anger standardkulturen för bearbetning av inkommande webbbegäranden. |
| CurrentConfiguration |
Hämtar en referens till den översta instansen Configuration som representerar konfigurationshierarkin som den aktuella ConfigurationElement instansen tillhör. (Ärvd från ConfigurationElement) |
| ElementInformation |
Hämtar ett ElementInformation objekt som innehåller den icke-anpassningsbara informationen och funktionerna i ConfigurationElement objektet. (Ärvd från ConfigurationElement) |
| ElementProperty |
Hämtar objektet ConfigurationElementProperty som representerar ConfigurationElement själva objektet. (Ärvd från ConfigurationElement) |
| EnableBestFitResponseEncoding |
Hämtar eller anger ett värde som anger om kodningen för bästa möjliga tecken för ett svar är aktiverad. |
| EnableClientBasedCulture |
Hämtar eller anger ett värde som anger om Culture egenskaperna och UICulture ska baseras på AcceptLanguage det rubrikfältvärde som skickas av klientwebbläsaren. |
| EvaluationContext |
Hämtar ContextInformation-objektet för ConfigurationElement-objektet. (Ärvd från ConfigurationElement) |
| FileEncoding |
Hämtar eller anger ett värde som anger standardkodning för .aspx, .asmx och .asax-filparsing. |
| HasContext |
Hämtar ett värde som anger om egenskapen CurrentConfiguration är |
| Item[ConfigurationProperty] |
Hämtar eller anger en egenskap eller ett attribut för det här konfigurationselementet. (Ärvd från ConfigurationElement) |
| Item[String] |
Hämtar eller anger en egenskap, ett attribut eller ett underordnat element i det här konfigurationselementet. (Ärvd från ConfigurationElement) |
| LockAllAttributesExcept |
Hämtar samlingen med låsta attribut. (Ärvd från ConfigurationElement) |
| LockAllElementsExcept |
Hämtar samlingen med låsta element. (Ärvd från ConfigurationElement) |
| LockAttributes |
Hämtar samlingen med låsta attribut. (Ärvd från ConfigurationElement) |
| LockElements |
Hämtar samlingen med låsta element. (Ärvd från ConfigurationElement) |
| LockItem |
Hämtar eller anger ett värde som anger om elementet är låst. (Ärvd från ConfigurationElement) |
| Properties |
Hämtar samlingen med egenskaper. (Ärvd från ConfigurationElement) |
| RequestEncoding |
Hämtar eller anger ett värde som anger innehållskodning för HTTP-begäranden. |
| ResourceProviderFactoryType |
Hämtar eller anger resursproviderns fabrikstyp. |
| ResponseEncoding |
Hämtar eller anger ett värde som anger innehållskodning för HTTP-svar. |
| ResponseHeaderEncoding |
Hämtar eller anger ett värde som anger rubrikkodningen för HTTP-svar. |
| SectionInformation |
Hämtar ett SectionInformation objekt som innehåller den icke-anpassningsbara informationen och funktionerna i ConfigurationSection objektet. (Ärvd från ConfigurationSection) |
| UICulture |
Hämtar eller anger ett värde som anger standardkulturen för bearbetning av språkberoende resurssökningar. |
Metoder
| Name | Description |
|---|---|
| DeserializeElement(XmlReader, Boolean) |
Läser XML från konfigurationsfilen. (Ärvd från ConfigurationElement) |
| DeserializeSection(XmlReader) |
Läser XML från konfigurationsfilen. (Ärvd från ConfigurationSection) |
| Equals(Object) |
Jämför den aktuella ConfigurationElement instansen med det angivna objektet. (Ärvd från ConfigurationElement) |
| GetHashCode() |
Hämtar ett unikt värde som representerar den aktuella ConfigurationElement instansen. (Ärvd från ConfigurationElement) |
| GetRuntimeObject() |
Returnerar ett anpassat objekt när det åsidosättas i en härledd klass. (Ärvd från ConfigurationSection) |
| GetTransformedAssemblyString(String) |
Returnerar den transformerade versionen av det angivna sammansättningsnamnet. (Ärvd från ConfigurationElement) |
| GetTransformedTypeString(String) |
Returnerar den transformerade versionen av det angivna typnamnet. (Ärvd från ConfigurationElement) |
| GetType() |
Hämtar den aktuella instansen Type . (Ärvd från Object) |
| Init() |
Anger objektets ConfigurationElement ursprungliga tillstånd. (Ärvd från ConfigurationElement) |
| InitializeDefault() |
Används för att initiera en standarduppsättning med värden för ConfigurationElement objektet. (Ärvd från ConfigurationElement) |
| IsModified() |
Anger om det här konfigurationselementet har ändrats sedan det senast sparades eller lästes in när det implementerades i en härledd klass. (Ärvd från ConfigurationSection) |
| IsReadOnly() |
Hämtar ett värde som anger om objektet ConfigurationElement är skrivskyddat. (Ärvd från ConfigurationElement) |
| ListErrors(IList) |
Lägger till felen invalid-property i det här ConfigurationElement objektet, och i alla underelement, i den överförda listan. (Ärvd från ConfigurationElement) |
| MemberwiseClone() |
Skapar en ytlig kopia av den aktuella Object. (Ärvd från Object) |
| OnDeserializeUnrecognizedAttribute(String, String) |
Hämtar ett värde som anger om ett okänt attribut påträffas under deserialiseringen. (Ärvd från ConfigurationElement) |
| OnDeserializeUnrecognizedElement(String, XmlReader) |
Hämtar ett värde som anger om ett okänt element påträffas under deserialiseringen. (Ärvd från ConfigurationElement) |
| OnRequiredPropertyNotFound(String) |
Utlöser ett undantag när en obligatorisk egenskap inte hittas. (Ärvd från ConfigurationElement) |
| PostDeserialize() |
Anropas efter deserialisering. (Ärvd från ConfigurationElement) |
| PreSerialize(XmlWriter) |
Anropas före serialisering. (Ärvd från ConfigurationElement) |
| Reset(ConfigurationElement) |
Återställer objektets interna tillstånd ConfigurationElement , inklusive låsen och egenskapssamlingarna. (Ärvd från ConfigurationElement) |
| ResetModified() |
Återställer värdet för metoden till |
| SerializeElement(XmlWriter, Boolean) |
Skriver innehållet i det här konfigurationselementet till konfigurationsfilen när det implementeras i en härledd klass. (Ärvd från ConfigurationElement) |
| SerializeSection(ConfigurationElement, String, ConfigurationSaveMode) |
Skapar en XML-sträng som innehåller en icke-komprimerad vy av ConfigurationSection objektet som ett enda avsnitt för att skriva till en fil. (Ärvd från ConfigurationSection) |
| SerializeToXmlElement(XmlWriter, String) |
Skriver de yttre taggarna för det här konfigurationselementet till konfigurationsfilen när det implementeras i en härledd klass. (Ärvd från ConfigurationElement) |
| SetPropertyValue(ConfigurationProperty, Object, Boolean) |
Anger en egenskap till det angivna värdet. (Ärvd från ConfigurationElement) |
| SetReadOnly() |
Anger egenskapen IsReadOnly() för ConfigurationElement objektet och alla underelement. (Ärvd från ConfigurationElement) |
| ShouldSerializeElementInTargetVersion(ConfigurationElement, String, FrameworkName) |
Anger om det angivna elementet ska serialiseras när konfigurationsobjekthierarkin serialiseras för den angivna målversionen av .NET Framework. (Ärvd från ConfigurationSection) |
| ShouldSerializePropertyInTargetVersion(ConfigurationProperty, String, FrameworkName, ConfigurationElement) |
Anger om den angivna egenskapen ska serialiseras när konfigurationsobjekthierarkin serialiseras för den angivna målversionen av .NET Framework. (Ärvd från ConfigurationSection) |
| ShouldSerializeSectionInTargetVersion(FrameworkName) |
Anger om den aktuella ConfigurationSection-instansen ska serialiseras när konfigurationsobjekthierarkin serialiseras för den angivna målversionen av .NET Framework. (Ärvd från ConfigurationSection) |
| ToString() |
Returnerar en sträng som representerar det aktuella objektet. (Ärvd från Object) |
| Unmerge(ConfigurationElement, ConfigurationElement, ConfigurationSaveMode) |
Ändrar objektet ConfigurationElement för att ta bort alla värden som inte ska sparas. (Ärvd från ConfigurationElement) |