WebContext Class

Definition

Manages the path context for the current Web application. This class cannot be inherited.

C#
public sealed class WebContext
Inheritance
WebContext

Examples

The following example shows how to use the WebContext class.

C#
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();
    }
  }
}

Constructors

Properties

ApplicationLevel

Gets a WebApplicationLevel object that represents the path level of the current Web application.

ApplicationPath

Gets the application path of the current Web application.

LocationSubPath

Gets the location subpath of the Web application.

Path

Gets the current virtual path of the Web application.

Site

Gets the name of the current Web application.

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the application's configuration path.

Applies to

Produkt Wersje
.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