SecurityPolicySection Klass

Definition

Definierar konfigurationsinställningar som används för att stödja säkerhetsinfrastrukturen för ett webbprogram. Det går inte att ärva den här klassen.

public ref class SecurityPolicySection sealed : System::Configuration::ConfigurationSection
public sealed class SecurityPolicySection : System.Configuration.ConfigurationSection
type SecurityPolicySection = class
    inherit ConfigurationSection
Public NotInheritable Class SecurityPolicySection
Inherits ConfigurationSection
Arv

Exempel

Det här exemplet visar hur du anger värden deklarativt i securityPolicy avsnittet, som också kan nås som medlemmar i SecurityPolicySection klassen.

Följande konfigurationsfilexempel visar hur du anger värden deklarativt för securityPolicy avsnittet.

<system.web>
  <securityPolicy>
    <trustLevel name="Full" policyFile="internal" />
    <trustLevel name="High" policyFile="web_hightrust.config" />
    <trustLevel name="Medium" policyFile="web_mediumtrust.config" />
    <trustLevel name="Low" policyFile="web_lowtrust.config" />
    <trustLevel name="Minimal" policyFile="web_minimaltrust.config" />
  </securityPolicy>
</system.web>

Följande kodexempel visar hur du SecurityPolicySection 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 UsingSecurityPolicySection
  {
    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.
        SecurityPolicySection configSection =
          (SecurityPolicySection)config.GetSection("system.web/securityPolicy");

        // 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 the number of trust levels.
        Console.WriteLine("TrustLevels Collection Count: {0}",
          configSection.TrustLevels.Count);

        // Display elements of the TrustLevels collection property.
        for (int i = 0; i < configSection.TrustLevels.Count; i++) 
        {
          Console.WriteLine();
          Console.WriteLine("TrustLevel {0}:", i);
          Console.WriteLine("Name: {0}", 
            configSection.TrustLevels.Get(i).Name);
          Console.WriteLine("Type: {0}", 
            configSection.TrustLevels.Get(i).PolicyFile);
        }

        // Add a TrustLevel element to the configuration file.
        configSection.TrustLevels.Add(new TrustLevel("myTrust", "mytrust.config"));

        // 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 UsingSecurityPolicySection
    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 = _
         System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(configPath)

                ' Get the section-related object.
        Dim configSection As System.Web.Configuration.SecurityPolicySection = _
         CType(config.GetSection("system.web/securityPolicy"), _
         System.Web.Configuration.SecurityPolicySection)

        ' 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 the number of trust levels.
        Console.WriteLine("TrustLevels Collection Count: {0}", _
          configSection.TrustLevels.Count)

        ' Display elements of the TrustLevels collection property.
        For i As Integer = 0 To (configSection.TrustLevels.Count - 1)
          Console.WriteLine()
          Console.WriteLine("TrustLevel {0}:", i)
          Console.WriteLine("Name: {0}", _
           configSection.TrustLevels.Get(i).Name)
          Console.WriteLine("Type: {0}", _
           configSection.TrustLevels.Get(i).PolicyFile)
        Next i

        ' Add a TrustLevel element to the configuration file.
        configSection.TrustLevels.Add(New TrustLevel("myTrust", "mytrust.config"))

        ' 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 SecurityPolicySection ger ett sätt att programmatiskt komma åt och ändra innehållet i securityPolicy avsnittet i konfigurationsfilen.

Konstruktorer

Name Description
SecurityPolicySection()

Initierar en ny instans av SecurityPolicySection klassen med hjälp av standardinställningar.

Egenskaper

Name Description
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)
EvaluationContext

Hämtar ContextInformation-objektet för ConfigurationElement-objektet.

(Ärvd från ConfigurationElement)
HasContext

Hämtar ett värde som anger om egenskapen CurrentConfiguration är null.

(Ärvd från ConfigurationElement)
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)
SectionInformation

Hämtar ett SectionInformation objekt som innehåller den icke-anpassningsbara informationen och funktionerna i ConfigurationSection objektet.

(Ärvd från ConfigurationSection)
TrustLevels

Hämtar samlingen TrustLevels .

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 false när den IsModified() implementeras i en härledd klass.

(Ärvd från ConfigurationSection)
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)

Gäller för

Se även