Name

HttpContext

Synopsis

The HttpContext class represents the “operating context” of an ASP.NET application. It provides references to instances of fundamental classes like HttpApplicationState and HttpRequest, which are known as intrinsic or “built-in” objects. The HttpContext class is provided to IHttpModule and IHttpHandler instances (like System.Web.UI.Page and HttpApplication), which provide these classes through their own properties. The shared (static) property Current returns the current HttpContext, and is useful if you need to access the built-in ASP.NET objects from another code module like a class (where you won’t have access to the System.Web.UI.Page properties). One example is a web service that doesn’t inherit from System.Web.Services.WebService. You can also use the shared GetAppConfig() method to retrieve a collection object from the web.config file that contains configuration information. Just specify the configuration section you want to examine as a parameter (like “appSettings”).

If you are creating your own IHttpHandler class, you will receive the current instance of the HttpContext class as a parameter of the IHttpHandler.ProcessRequest() method. To use the Session property of the HttpContext lass, you must also implement either the System.Web.SessionState.IReadOnlySessionState interface or the System.Web.SessionState.IRequiresSessionState interface.

Public NotInheritable Class HttpContext : Implements IServiceProvider
' Public Constructors
   Public Sub New ...

Get ASP.NET in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.