WebContext 类

定义

管理当前 Web 应用程序的路径上下文。 此类不能被继承。

public ref class WebContext sealed
public sealed class WebContext
type WebContext = class
Public NotInheritable Class WebContext
继承
WebContext

示例

下面的示例演示如何使用 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

构造函数

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

初始化 WebContext 类的新实例。

属性

ApplicationLevel

获取 WebApplicationLevel 对象,它表示当前 Web 应用程序的路径级别。

ApplicationPath

获取当前 Web 应用程序的应用程序路径。

LocationSubPath

获取 Web 应用程序的位置子路径。

Path

获取 Web 应用程序的当前虚拟路径。

Site

获取当前 Web 应用程序的名称。

方法

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示应用程序的配置路径的字符串。

适用于