WebContext Class
TOC
Collapse the table of content
Expand the table of content

WebContext Class

 

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

Namespace:   System.Web.Configuration
Assembly:  System.Web (in System.Web.dll)

System.Object
  System.Web.Configuration.WebContext

public sealed class WebContext

NameDescription
System_CAPS_pubmethodWebContext(WebApplicationLevel, String, String, String, String, String)

Initializes a new instance of the WebContext class.

NameDescription
System_CAPS_pubpropertyApplicationLevel

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

System_CAPS_pubpropertyApplicationPath

Gets the application path of the current Web application.

System_CAPS_pubpropertyLocationSubPath

Gets the location subpath of the Web application.

System_CAPS_pubpropertyPath

Gets the current virtual path of the Web application.

System_CAPS_pubpropertySite

Gets the name of the current Web application.

NameDescription
System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodToString()

Returns a string that represents the application's configuration path.(Overrides Object.ToString().)

The following example shows how to use the WebContext class.

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

.NET Framework
Available since 2.0

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show:
© 2016 Microsoft