ContextInformation Classe
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Encapsula as informações de contexto que estão associadas a um objeto ConfigurationElement. Essa classe não pode ser herdada.
public ref class ContextInformation sealed
public sealed class ContextInformation
type ContextInformation = class
Public NotInheritable Class ContextInformation
- Herança
-
ContextInformation
O exemplo de código a seguir demonstra como usar o ContextInformation tipo .
#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.ConfigurationSample
{
class UsingContextInformation
{
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.
HealthMonitoringSection configSection =
(HealthMonitoringSection)config.GetSection("system.web/healthMonitoring");
// 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);
// IsMachineLevel property.
Console.WriteLine("IsMachineLevel: {0}",
config.EvaluationContext.IsMachineLevel);
// Create an object based on HostingContext.
WebContext myWC =
(WebContext)config.EvaluationContext.HostingContext;
// Use the WebContext object to determine
// the ApplicationLevel.
Console.WriteLine("ApplicationLevel: {0}",
myWC.ApplicationLevel);
}
catch (Exception e)
{
// Error.
Console.WriteLine(e.ToString());
}
// Display and wait.
Console.ReadLine();
}
}
}
Imports System.Collections
Imports System.Collections.Generic
Imports System.Text
Imports System.Configuration
Imports System.Web
Imports System.Web.Configuration
Namespace Samples.Aspnet.ConfigurationSample
Class UsingContextInformation
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 Configuration = _
WebConfigurationManager.OpenWebConfiguration(configPath)
' Get the section related object.
Dim configSection As _
System.Web.Configuration.HealthMonitoringSection = _
CType(config.GetSection("system.web/healthMonitoring"), _
System.Web.Configuration.HealthMonitoringSection)
' 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)
' IsMachineLevel property.
Console.WriteLine("IsMachineLevel: {0}", _
config.EvaluationContext.IsMachineLevel)
' Create an object based on HostingContext.
Dim myWC As WebContext = _
config.EvaluationContext.HostingContext
' Use the WebContext object to determine
' the ApplicationLevel.
Console.WriteLine("ApplicationLevel: {0}", _
myWC.ApplicationLevel)
Catch e As System.Exception
' Error.
Console.WriteLine(e.ToString())
End Try
' Display and wait.
Console.ReadLine()
End Sub
End Class
End Namespace
O ContextInformation objeto fornece detalhes de ambiente relacionados a um elemento da configuração. Por exemplo, você pode usar a IsMachineLevel propriedade para determinar se um ConfigurationElement foi definido em Machine.config ou pode determinar a qual hierarquia pertence ConfigurationElement usando a HostingContext propriedade .
Hosting |
Obtém o contexto do ambiente em que a propriedade de configuração está sendo avaliada. |
Is |
Obtém um valor que especifica se a propriedade de configuração está sendo avaliada no nível de configuração do computador. |
Equals(Object) |
Determina se o objeto especificado é igual ao objeto atual. (Herdado de Object) |
Get |
Serve como a função de hash padrão. (Herdado de Object) |
Get |
Fornece um objeto que contém informações de seção de configuração com base no nome da seção especificada. |
Get |
Obtém o Type da instância atual. (Herdado de Object) |
Memberwise |
Cria uma cópia superficial do Object atual. (Herdado de Object) |
To |
Retorna uma cadeia de caracteres que representa o objeto atual. (Herdado de Object) |
Produto | Versões |
---|---|
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |
Comentários do .NET
O .NET é um projeto código aberto. Selecione um link para fornecer comentários: