WebContext Class
.NET Framework 4.5
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)
The WebContext type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | 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. |
| Name | Description | |
|---|---|---|
![]() | Equals(Object) | Determines whether the specified object is equal to the current object. (Inherited from Object.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | ToString | 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(); } } }
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
