WebContext Clase

Definición

Administra el contexto de la ruta de acceso para la aplicación web actual. Esta clase no puede heredarse.

public ref class WebContext sealed
public sealed class WebContext
type WebContext = class
Public NotInheritable Class WebContext
Herencia
WebContext

Ejemplos

En el siguiente ejemplo, se muestra cómo utilizar la clase WebContext.

using System;
using System.Configuration;
using System.Web;
using System.Web.Configuration;

namespace WebContextTest01cs
{
  class UsingWebContext
  {
    static void Main(string[] args)
    {
      try
      {
        // Set the path of the config file.
        string configPath = "/aspnet";

        // Get the Web application configuration object.
        Configuration config =
          WebConfigurationManager.OpenWebConfiguration(configPath);

        // Get the context.
        WebContext webContext = (WebContext)config.EvaluationContext.HostingContext;

        // Display title.
        Console.WriteLine("ASP.NET WebContext Info");
        Console.WriteLine("");

        // WebContext - Application Level.
        Console.WriteLine("ApplicationLevel: {0}", 
          webContext.ApplicationLevel.ToString());
        // WebContext - Application Path.
        Console.WriteLine("ApplicationPath: {0}", 
          webContext.ApplicationPath.ToString());
        // WebContext - Path.
        Console.WriteLine("Path: {0}", webContext.Path.ToString());
        // WebContext - Site.
        Console.WriteLine("Site: {0}", webContext.Site.ToString());
      }
      catch (Exception ex)
      {
        // Unknown error.
        Console.WriteLine(ex.ToString());
      }

      // Display and wait.
      Console.ReadLine();
    }
  }
}
Imports System.Configuration
Imports System.Web
Imports System.Web.Configuration

Namespace Samples.Aspnet.SystemWebConfiguration
  Class UsingWebContext
    Public Shared Sub Main()
      Try
        ' Set the path of the config file.
        Dim configPath As String = "/aspnet"

        ' Get the Web application configuration object.
        Dim config As Configuration = _
         WebConfigurationManager.OpenWebConfiguration(configPath)

        ' Get the context.
        Dim webContext As WebContext = config.EvaluationContext.HostingContext

        ' Display title and info.
        Console.WriteLine("ASP.NET WebContext Info")
        Console.WriteLine()

        ' WebContext - Application Level.
        Console.WriteLine("ApplicationLevel: {0}", _
          webContext.ApplicationLevel.ToString())
        ' WebContext - Application Path.
        Console.WriteLine("ApplicationPath: {0}", _
          webContext.ApplicationPath.ToString())
        ' WebContext - Path.
        Console.WriteLine("Path: {0}", webContext.Path.ToString())
        ' WebContext - Site.
        Console.WriteLine("Site: {0}", webContext.Site.ToString())

      Catch e As Exception
        ' Unknown error.
        Console.WriteLine(e.ToString())
      End Try

      ' Display and wait
      Console.ReadLine()
    End Sub
  End Class
End Namespace

Constructores

WebContext(WebApplicationLevel, String, String, String, String, String)

Inicializa una nueva instancia de la clase WebContext.

Propiedades

ApplicationLevel

Obtiene un objeto WebApplicationLevel que representa el nivel de ruta de acceso de la aplicación web actual.

ApplicationPath

Obtiene la ruta de acceso de la aplicación web actual.

LocationSubPath

Obtiene la subruta de ubicación de la aplicación web.

Path

Obtiene la ruta de acceso virtual actual de la aplicación web.

Site

Obtiene el nombre de la aplicación web actual.

Métodos

Equals(Object)

Determina si el objeto especificado es igual que el objeto actual.

(Heredado de Object)
GetHashCode()

Sirve como la función hash predeterminada.

(Heredado de Object)
GetType()

Obtiene el Type de la instancia actual.

(Heredado de Object)
MemberwiseClone()

Crea una copia superficial del Object actual.

(Heredado de Object)
ToString()

Devuelve una cadena que representa la ruta de acceso de configuración de la aplicación.

Se aplica a