WebContext Class
.NET Framework 3.5
Manages the path context for the current Web application. This class cannot be inherited.
Assembly: System.Web (in System.Web.dll)
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 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.