ProfileSection Třída

Definice

Třída ProfileSection poskytuje způsob, jak programově přistupovat a upravovat profile oddíl konfiguračního souboru. Tuto třídu nelze zdědit.

public ref class ProfileSection sealed : System::Configuration::ConfigurationSection
public sealed class ProfileSection : System.Configuration.ConfigurationSection
type ProfileSection = class
    inherit ConfigurationSection
Public NotInheritable Class ProfileSection
Inherits ConfigurationSection
Dědičnost

Příklady

Následující výňatek konfiguračního ProfileSection souboru ukazuje, jak deklarativní zadat hodnoty pro několik vlastností třídy.

<system.web>  
  <profile enabled = "true"   
     defaultProvider="AspNetSqlProfileProvider">  
    <providers>  
      <add  name="AspNetSqlProfileProvider"  
        type="System.Web.Profile.SqlProfileProvider"  
        connectionStringName="LocalSqlServer"  
        applicationName="/"  
        description="Stores and retrieves profile data from the   
local Microsoft SQL Server database" />  
    </providers>  
    <properties>  
      <add name = "FirstName"/>  
      <add name = "LastName"/>  
      <add name = "FavoriteURLs" type =  
        "System.Collection.Specialized.StringCollection, System"   
        serializeAs = "Xml"/>        
      <add name = "ShoppingCart" type =   
        "MyCommerce.ShoppingCart, MyCommerce"   
        serializeAs = "Binary"/>  
      <group name = "SiteColors" >  
        <add name = "BackGround"/>  
        <add name = "SideBar"/>  
        <add name = "ForeGroundText"/>  
        <add name = "ForeGroundBorders"/>  
      </group>  
      <group name="Forums">  
        <add name = "HasAvatar" type="bool" provider="Forums"/>  
        <add name = "LastLogin" type="DateTime" provider="Forums"/>  
        <add name = "TotalPosts" type="int" provider="Forums"/>  
      </group>  
    </properties>  
  </profile>  
</system.web>  

Následující příklad kódu ukazuje, jak použít ProfileSection typ.

using System;
using System.Collections;
using System.Collections.Specialized;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Configuration;
using System.Web.Configuration;

namespace Samples.Aspnet.SystemWebConfiguration
{
    // Accesses the System.Web.Configuration.ProfileSection members
    // selected by the user.
    class UsingProfileSection
    {
        public static void Main()
        {
            // Process the System.Web.Configuration.ProfileSectionobject.
            try
            {
                // Get the Web application configuration.
                System.Configuration.Configuration configuration = 
                    System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/aspnet");
                
                // Get the section.
                System.Web.Configuration.ProfileSection profileSection = 
                    (System.Web.Configuration.ProfileSection) 
                    configuration.GetSection("system.web/profile");

// Get the current AutomaticSaveEnabled property value.
Console.WriteLine(
    "Current AutomaticSaveEnabled value: '{0}'", profileSection.AutomaticSaveEnabled);

// Set the AutomaticSaveEnabled property to false.
profileSection.AutomaticSaveEnabled = false;

                

// Get the current DefaultProvider property value.
Console.WriteLine(
    "Current DefaultProvider value: '{0}'", profileSection.DefaultProvider);

// Set the DefaultProvider property to "AspNetSqlProvider".
profileSection.DefaultProvider = "AspNetSqlProvider";

                

// Get the current Inherits property value.
Console.WriteLine(
    "Current Inherits value: '{0}'", profileSection.Inherits);

// Set the Inherits property to
// "CustomProfiles.MyCustomProfile, CustomProfiles.dll".
profileSection.Inherits = "CustomProfiles.MyCustomProfile, CustomProfiles.dll";

                

// Display all current root ProfilePropertySettings.
Console.WriteLine("Current Root ProfilePropertySettings:");
int rootPPSCtr = 0;
foreach (ProfilePropertySettings rootPPS in profileSection.PropertySettings)
{
    Console.WriteLine("  {0}: ProfilePropertySetting '{1}'", ++rootPPSCtr,
        rootPPS.Name);
}

// Get and modify a root ProfilePropertySettings object.
Console.WriteLine(
    "Display and modify 'LastReadDate' ProfilePropertySettings:");
ProfilePropertySettings profilePropertySettings =
    profileSection.PropertySettings["LastReadDate"];

// Get the current ReadOnly property value.
Console.WriteLine(
    "Current ReadOnly value: '{0}'", profilePropertySettings.ReadOnly);

// Set the ReadOnly property to true.
profilePropertySettings.ReadOnly = true;

// Get the current AllowAnonymous property value.
Console.WriteLine(
    "Current AllowAnonymous value: '{0}'", profilePropertySettings.AllowAnonymous);

// Set the AllowAnonymous property to true.
profilePropertySettings.AllowAnonymous = true;

// Get the current SerializeAs property value.
Console.WriteLine(
    "Current SerializeAs value: '{0}'", profilePropertySettings.SerializeAs);

// Set the SerializeAs property to SerializationMode.Binary.
profilePropertySettings.SerializeAs = SerializationMode.Binary;

// Get the current Type property value.
Console.WriteLine(
    "Current Type value: '{0}'", profilePropertySettings.Type);

// Set the Type property to "System.DateTime".
profilePropertySettings.Type = "System.DateTime";

// Get the current DefaultValue property value.
Console.WriteLine(
    "Current DefaultValue value: '{0}'", profilePropertySettings.DefaultValue);

// Set the DefaultValue property to "March 16, 2004".
profilePropertySettings.DefaultValue = "March 16, 2004";

// Get the current ProviderName property value.
Console.WriteLine(
    "Current ProviderName value: '{0}'", profilePropertySettings.Provider);

// Set the ProviderName property to "AspNetSqlRoleProvider".
profilePropertySettings.Provider = "AspNetSqlRoleProvider";

// Get the current Name property value.
Console.WriteLine(
    "Current Name value: '{0}'", profilePropertySettings.Name);

// Set the Name property to "LastAccessDate".
profilePropertySettings.Name = "LastAccessDate";

// Display all current ProfileGroupSettings.
Console.WriteLine("Current ProfileGroupSettings:");
int PGSCtr = 0;
foreach (ProfileGroupSettings propGroups in profileSection.PropertySettings.GroupSettings)
{
    Console.WriteLine("  {0}: ProfileGroupSetting '{1}'", ++PGSCtr,
        propGroups.Name);
    int PPSCtr = 0;
    foreach (ProfilePropertySettings props in propGroups.PropertySettings)
    {
        Console.WriteLine("    {0}: ProfilePropertySetting '{1}'", ++PPSCtr,
            props.Name);
    }
}

// Add a new group.
ProfileGroupSettings newPropGroup = new ProfileGroupSettings("Forum");
profileSection.PropertySettings.GroupSettings.Add(newPropGroup);

// Add a new PropertySettings to the group.
ProfilePropertySettings newProp = new ProfilePropertySettings("AvatarImage");
newProp.Type = "System.String, System.dll";
newPropGroup.PropertySettings.Add(newProp);

// Remove a PropertySettings from the group.
newPropGroup.PropertySettings.Remove("AvatarImage");
newPropGroup.PropertySettings.RemoveAt(0);

// Clear all PropertySettings from the group.
newPropGroup.PropertySettings.Clear();

                

// Display all current Providers.
Console.WriteLine("Current Providers:");
int providerCtr = 0;
foreach (ProviderSettings provider in profileSection.Providers)
{
    Console.WriteLine("  {0}: Provider '{1}' of type '{2}'", ++providerCtr, 
        provider.Name, provider.Type);
}

// Add a new provider.
profileSection.Providers.Add(new ProviderSettings("AspNetSqlProvider", "...SqlProfileProvider"));

                

// Get the current Enabled property value.
Console.WriteLine(
    "Current Enabled value: '{0}'", profileSection.Enabled);

// Set the Enabled property to false.
profileSection.Enabled = false;

                
                // Update if not locked.
                if (! profileSection.SectionInformation.IsLocked)
                {
                    configuration.Save();
                    Console.WriteLine("** Configuration updated.");
                }
                else
                {
                    Console.WriteLine("** Could not update, section is locked.");
                }
            }
            catch (System.ArgumentException e)
            {
                // Unknown error.
                Console.WriteLine(
                    "A invalid argument exception detected in UsingProfileSection Main. Check your");
                Console.WriteLine("command line for errors.");
            }
        }
    } // UsingProfileSection class end.
} // Samples.Aspnet.SystemWebConfiguration namespace end.
Imports System.Collections
Imports System.Collections.Specialized
Imports System.IO
Imports System.Text
Imports System.Text.RegularExpressions
Imports System.Configuration
Imports System.Web.Configuration

Namespace Samples.Aspnet.SystemWebConfiguration
    ' Accesses the System.Web.Configuration.ProfileSection members
    ' selected by the user.
    Class UsingProfileSection
        Public Shared Sub Main()
            ' Process the System.Web.Configuration.ProfileSectionobject.
            Try
                ' Get the Web application configuration.
                Dim configuration As System.Configuration.Configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/aspnet")
                
                ' Get the section.
                Dim profileSection As System.Web.Configuration.ProfileSection = CType(configuration.GetSection("system.web/profile"), System.Web.Configuration.ProfileSection)

' Get the current AutomaticSaveEnabled property value.
Console.WriteLine( _
    "Current AutomaticSaveEnabled value: '{0}'", profileSection.AutomaticSaveEnabled)

' Set the AutomaticSaveEnabled property to false.
profileSection.AutomaticSaveEnabled = false

                

' Get the current DefaultProvider property value.
Console.WriteLine( _
    "Current DefaultProvider value: '{0}'", profileSection.DefaultProvider)

' Set the DefaultProvider property to "AspNetSqlProvider".
profileSection.DefaultProvider = "AspNetSqlProvider"

                

' Get the current Inherits property value.
Console.WriteLine( _
    "Current Inherits value: '{0}'", profileSection.Inherits)

' Set the Inherits property to
' "CustomProfiles.MyCustomProfile, CustomProfiles.dll".
profileSection.Inherits = "CustomProfiles.MyCustomProfile, CustomProfiles.dll"

                


' Display all current root ProfilePropertySettings.
Console.WriteLine("Current Root ProfilePropertySettings:")
Dim rootPPSCtr As Integer = 0
For Each rootPPS As ProfilePropertySettings In profileSection.PropertySettings
    Console.WriteLine("  {0}: ProfilePropertySetting '{1}'", ++rootPPSCtr, _
        rootPPS.Name)
Next

' Get and modify a root ProfilePropertySettings object.
Console.WriteLine( _
    "Display and modify 'LastReadDate' ProfilePropertySettings:")
Dim profilePropertySettings As ProfilePropertySettings = _
    profileSection.PropertySettings("LastReadDate")

' Get the current ReadOnly property value.
Console.WriteLine( _
    "Current ReadOnly value: '{0}'", profilePropertySettings.ReadOnly)

' Set the ReadOnly property to true.
profilePropertySettings.ReadOnly = true

' Get the current AllowAnonymous property value.
Console.WriteLine( _
    "Current AllowAnonymous value: '{0}'", profilePropertySettings.AllowAnonymous)

' Set the AllowAnonymous property to true.
profilePropertySettings.AllowAnonymous = true

' Get the current SerializeAs property value.
Console.WriteLine( _
    "Current SerializeAs value: '{0}'", profilePropertySettings.SerializeAs)

' Set the SerializeAs property to SerializationMode.Binary.
profilePropertySettings.SerializeAs = SerializationMode.Binary

' Get the current Type property value.
Console.WriteLine( _
    "Current Type value: '{0}'", profilePropertySettings.Type)

' Set the Type property to "System.DateTime".
profilePropertySettings.Type = "System.DateTime"

' Get the current DefaultValue property value.
Console.WriteLine( _
    "Current DefaultValue value: '{0}'", profilePropertySettings.DefaultValue)

' Set the DefaultValue property to "March 16, 2004".
profilePropertySettings.DefaultValue = "March 16, 2004"

' Get the current ProviderName property value.
            Console.WriteLine( _
                "Current ProviderName value: '{0}'", profilePropertySettings.Provider)

' Set the ProviderName property to "AspNetSqlRoleProvider".
            profilePropertySettings.Provider = "AspNetSqlRoleProvider"

' Get the current Name property value.
Console.WriteLine( _
    "Current Name value: '{0}'", profilePropertySettings.Name)

' Set the Name property to "LastAccessDate".
profilePropertySettings.Name = "LastAccessDate"

' Display all current ProfileGroupSettings.
Console.WriteLine("Current ProfileGroupSettings:")
Dim PGSCtr As Integer = 0
For Each propGroups As ProfileGroupSettings In profileSection.PropertySettings.GroupSettings
                    Console.WriteLine("  {0}: ProfileGroupSettings '{1}'", ++PGSCtr, _
        propGroups.Name)
    Dim PPSCtr As Integer = 0
    For Each props As ProfilePropertySettings In propGroups.PropertySettings
        Console.WriteLine("    {0}: ProfilePropertySetting '{1}'", ++PPSCtr, _
            props.Name)
    Next
Next

' Add a new group.
Dim newPropGroup As ProfileGroupSettings = new ProfileGroupSettings("Forum")
profileSection.PropertySettings.GroupSettings.Add(newPropGroup)

' Add a new PropertySettings to the group.
Dim newProp As ProfilePropertySettings = new ProfilePropertySettings("AvatarImage")
newProp.Type = "System.String, System.dll"
newPropGroup.PropertySettings.Add(newProp)

' Remove a PropertySettings from the group.
newPropGroup.PropertySettings.Remove("AvatarImage")
newPropGroup.PropertySettings.RemoveAt(0)

' Clear all PropertySettings from the group.
newPropGroup.PropertySettings.Clear()

                

Console.WriteLine("Current Providers:")
Dim providerCtr As Integer = 0
For Each provider As ProviderSettings In profileSection.Providers
    Console.WriteLine("  {0}: Provider '{1}' of type '{2}'", ++providerCtr, _
        provider.Name, provider.Type)
Next

' Add a new provider.
profileSection.Providers.Add(new ProviderSettings("AspNetSqlProvider", "...SqlProfileProvider"))

                

' Get the current Enabled property value.
Console.WriteLine( _
    "Current Enabled value: '{0}'", profileSection.Enabled)

' Set the Enabled property to false.
profileSection.Enabled = false

                
                ' Update if not locked.
                If Not profileSection.SectionInformation.IsLocked Then
                    configuration.Save()
                    Console.WriteLine("** Configuration updated.")
                Else
                    Console.WriteLine("** Could not update, section is locked.")
                End If
            Catch e As System.ArgumentException
                ' Unknown error.
                Console.WriteLine( _
                    "A invalid argument exception detected in UsingProfileSection Main. Check your")
                Console.WriteLine("command line for errors.")
            End Try
        End Sub
    End Class
    
End Namespace ' Samples.Aspnet.SystemWebConfiguration

Poznámky

Třída ProfileSection poskytuje způsob, jak programově přistupovat a upravovat obsah oddílu konfiguračního souboru profile . Část profile konfiguračního souboru určuje schéma profilů uživatelů. Za běhu ASP.NET systém kompilace používá informace zadané v oddílu profile k vygenerování třídy volané ProfileCommon, která je odvozena z ProfileBase. Definice ProfileCommon třídy je založená na vlastnostech definovaných v profile části konfiguračního souboru. Třída umožňuje přístup k jednotlivým profilům a jejich úpravě. Instance této třídy je vytvořena pro každý profil uživatele a můžete přistupovat k jednotlivým hodnotám profilu v kódu prostřednictvím HttpContext.Profile vlastnosti. Další informace o funkcích profilu přidaných do ASP.NET 2.0 najdete v tématu ASP.NET přehled vlastností profilu.

Konstruktory

ProfileSection()

Inicializuje novou instanci ProfileSection třídy pomocí výchozího nastavení.

Vlastnosti

AutomaticSaveEnabled

Získá nebo nastaví hodnotu, která určuje, zda se změny informací profilu uživatele automaticky ukládají na konec stránky.

CurrentConfiguration

Získá odkaz na instanci nejvyšší úrovně Configuration , která představuje hierarchii konfigurace, do které aktuální ConfigurationElement instance patří.

(Zděděno od ConfigurationElement)
DefaultProvider

Získá nebo nastaví název výchozího zprostředkovatele profilu.

ElementInformation

ElementInformation Získá objekt, který obsahuje neuzpůsobitelné informace a funkce objektuConfigurationElement.

(Zděděno od ConfigurationElement)
ElementProperty

ConfigurationElementProperty Získá objekt, který představuje ConfigurationElement samotný objekt.

(Zděděno od ConfigurationElement)
Enabled

Získá nebo nastaví hodnotu označující, zda je povolena funkce profilu ASP.NET.

EvaluationContext

ContextInformation Získá objekt objektuConfigurationElement.

(Zděděno od ConfigurationElement)
HasContext

Získá hodnotu, která označuje, zda CurrentConfiguration je nullvlastnost .

(Zděděno od ConfigurationElement)
Inherits

Získá nebo nastaví odkaz na typ pro vlastní typ odvozený od ProfileBase.

Item[ConfigurationProperty]

Získá nebo nastaví vlastnost nebo atribut tohoto konfiguračního prvku.

(Zděděno od ConfigurationElement)
Item[String]

Získá nebo nastaví vlastnost, atribut nebo podřízený prvek tohoto konfiguračního prvku.

(Zděděno od ConfigurationElement)
LockAllAttributesExcept

Získá kolekci uzamčených atributů.

(Zděděno od ConfigurationElement)
LockAllElementsExcept

Získá kolekci uzamčených prvků.

(Zděděno od ConfigurationElement)
LockAttributes

Získá kolekci uzamčených atributů.

(Zděděno od ConfigurationElement)
LockElements

Získá kolekci uzamčených prvků.

(Zděděno od ConfigurationElement)
LockItem

Získá nebo nastaví hodnotu určující, zda je prvek uzamčen.

(Zděděno od ConfigurationElement)
Properties

Získá kolekci vlastností.

(Zděděno od ConfigurationElement)
PropertySettings

RootProfilePropertySettingsCollection Získá kolekci ProfilePropertySettings objektů.

Providers

Získá kolekci ProviderSettings objektů.

SectionInformation

SectionInformation Získá objekt, který obsahuje ne přizpůsobitelné informace a funkce objektuConfigurationSection.

(Zděděno od ConfigurationSection)

Metody

DeserializeElement(XmlReader, Boolean)

Načte XML z konfiguračního souboru.

(Zděděno od ConfigurationElement)
DeserializeSection(XmlReader)

Načte XML z konfiguračního souboru.

(Zděděno od ConfigurationSection)
Equals(Object)

Porovná aktuální ConfigurationElement instanci se zadaným objektem.

(Zděděno od ConfigurationElement)
GetHashCode()

Získá jedinečnou hodnotu představující aktuální ConfigurationElement instanci.

(Zděděno od ConfigurationElement)
GetRuntimeObject()

Vrátí vlastní objekt při přepsání v odvozené třídě.

(Zděděno od ConfigurationSection)
GetTransformedAssemblyString(String)

Vrátí transformovanou verzi zadaného názvu sestavení.

(Zděděno od ConfigurationElement)
GetTransformedTypeString(String)

Vrátí transformovanou verzi zadaného názvu typu.

(Zděděno od ConfigurationElement)
GetType()

Type Získá aktuální instanci.

(Zděděno od Object)
Init()

ConfigurationElement Nastaví objekt na počáteční stav.

(Zděděno od ConfigurationElement)
InitializeDefault()

Slouží k inicializaci výchozí sady hodnot objektu ConfigurationElement .

(Zděděno od ConfigurationElement)
IsModified()

Označuje, zda byl tento element konfigurace změněn od posledního uložení nebo načtení při implementaci v odvozené třídě.

(Zděděno od ConfigurationSection)
IsReadOnly()

Získá hodnotu určující, zda ConfigurationElement objekt je jen pro čtení.

(Zděděno od ConfigurationElement)
ListErrors(IList)

Přidá chyby neplatné vlastnosti v tomto ConfigurationElement objektu a ve všech dílčích počtech do předaného seznamu.

(Zděděno od ConfigurationElement)
MemberwiseClone()

Vytvoří použádnou kopii aktuálního souboru Object.

(Zděděno od Object)
OnDeserializeUnrecognizedAttribute(String, String)

Získá hodnotu označující, zda je zjištěn neznámý atribut během deserializace.

(Zděděno od ConfigurationElement)
OnDeserializeUnrecognizedElement(String, XmlReader)

Získá hodnotu označující, zda je při deserializaci zjištěn neznámý prvek.

(Zděděno od ConfigurationElement)
OnRequiredPropertyNotFound(String)

Vyvolá výjimku, když se nenajde požadovaná vlastnost.

(Zděděno od ConfigurationElement)
PostDeserialize()

Volá se po deserializaci.

(Zděděno od ConfigurationElement)
PreSerialize(XmlWriter)

Volá se před serializací.

(Zděděno od ConfigurationElement)
Reset(ConfigurationElement)

Obnoví vnitřní stav objektu ConfigurationElement , včetně zámků a kolekcí vlastností.

(Zděděno od ConfigurationElement)
ResetModified()

Obnoví hodnotu IsModified() metody na false při implementaci v odvozené třídě.

(Zděděno od ConfigurationSection)
SerializeElement(XmlWriter, Boolean)

Zapíše obsah tohoto konfiguračního prvku do konfiguračního souboru při implementaci v odvozené třídě.

(Zděděno od ConfigurationElement)
SerializeSection(ConfigurationElement, String, ConfigurationSaveMode)

Vytvoří řetězec XML obsahující nemergované zobrazení ConfigurationSection objektu jako jeden oddíl pro zápis do souboru.

(Zděděno od ConfigurationSection)
SerializeToXmlElement(XmlWriter, String)

Zapíše vnější značky tohoto konfiguračního prvku do konfiguračního souboru při implementaci v odvozené třídě.

(Zděděno od ConfigurationElement)
SetPropertyValue(ConfigurationProperty, Object, Boolean)

Nastaví vlastnost na zadanou hodnotu.

(Zděděno od ConfigurationElement)
SetReadOnly()

IsReadOnly() Nastaví vlastnost pro ConfigurationElement objekt a všechny dílčí prvky.

(Zděděno od ConfigurationElement)
ShouldSerializeElementInTargetVersion(ConfigurationElement, String, FrameworkName)

Určuje, zda má být zadaný prvek serializován při serializaci hierarchie objektu konfigurace pro zadanou cílovou verzi .NET Framework.

(Zděděno od ConfigurationSection)
ShouldSerializePropertyInTargetVersion(ConfigurationProperty, String, FrameworkName, ConfigurationElement)

Určuje, zda má být zadaná vlastnost serializována, pokud je hierarchie objektu konfigurace serializována pro zadanou cílovou verzi .NET Framework.

(Zděděno od ConfigurationSection)
ShouldSerializeSectionInTargetVersion(FrameworkName)

Určuje, zda má být aktuální ConfigurationSection instance serializována, když je hierarchie objektu konfigurace serializována pro zadanou cílovou verzi .NET Framework.

(Zděděno od ConfigurationSection)
ToString()

Vrátí řetězec, který představuje aktuální objekt.

(Zděděno od Object)
Unmerge(ConfigurationElement, ConfigurationElement, ConfigurationSaveMode)

Upraví objekt tak, ConfigurationElement aby odebral všechny hodnoty, které by neměly být uloženy.

(Zděděno od ConfigurationElement)

Platí pro

Viz také