HostingEnvironmentSection Klass

Definition

Definierar konfigurationsinställningar som styr beteendet för programvärdmiljön. Det går inte att ärva den här klassen.

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

Exempel

Det här exemplet visar hur du anger värden deklarativt för flera attribut i avsnittet hostingEnvironment Element (ASP.NET Settings Schema), som också kan nås som medlemmar i klassen HostingEnvironmentSection.

Följande konfigurationsfilexempel visar hur du anger värden deklarativt för avsnittet hostingEnvironment Element (ASP.NET Settings Schema).

<system.web>
  <hostingEnvironment
    idleTimeout="20"
    shutdownTimeout="30"
  />
</system.web>

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

        // 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 IdleTimout property
        Console.WriteLine("Idle Timeout: {0}", configSection.IdleTimeout);

        // Set IdleTimout property
        configSection.IdleTimeout = TimeSpan.FromMinutes(40);

        // Display ShutdownTimeout property
        Console.WriteLine("Shutdown Timeout: {0}", configSection.ShutdownTimeout);

        // Set ShutdownTimeout property
        configSection.ShutdownTimeout = TimeSpan.FromSeconds(60);

        // 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 UsingSiteMapSection
    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.HostingEnvironmentSection = _
         CType(config.GetSection("system.web/hostingEnvironment"), System.Web.Configuration.HostingEnvironmentSection)

        ' 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 IdleTimout property
        Console.WriteLine("Idle Timeout: {0}", configSection.IdleTimeout)

        ' Set the IdleTimout property
        configSection.IdleTimeout = TimeSpan.FromMinutes(40)

        ' Display the ShutdownTimeout property
        Console.WriteLine("Shutdown Timeout: {0}", configSection.ShutdownTimeout)

        ' Set the ShutdownTimeout property
        configSection.ShutdownTimeout = TimeSpan.FromSeconds(60)

        ' 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 HostingEnvironmentSection ger ett sätt att programmatiskt komma åt och ändra värdena för avsnittet HostingEnvironmentSection i konfigurationsfilen. När ett ASP.NET program inte används under en angiven tid kan det tas bort från minnet baserat på egenskaperna IdleTimeout och ShutdownTimeout.

Konstruktorer

Name Description
HostingEnvironmentSection()

Initierar en ny instans av HostingEnvironmentSection 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)
IdleTimeout

Hämtar eller anger hur lång tid, i minuter, innan ett inaktivt program tas bort.

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)
ShadowCopyBinAssemblies

Hämtar eller anger ett värde som anger om sammansättningarna för ett program i bin kopieras till programmets katalog ASP.NET Temporary Files.

ShutdownTimeout

Hämtar eller anger hur lång tid i sekunder programmet ska stängas av.

UrlMetadataSlidingExpiration

Hämtar eller anger ett värde som avgör hur ASP.NET cachelagrar URL-metadata.

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