Class Capability Differences

  • Thread starter Thread starter Jeff S
  • Start date Start date
J

Jeff S

Just wondering why some features are available from the code-behind class
modules (.aspx.cs), and are not available from stand-alone class modules
(myClass.cs). For example, accessing the Application state is no problem
from a code-behind, but not from a stand-alone module in the same assembly.
Is it that code-behind modules inherit Page? Is there more to it?

Thanks.
 
Use System.Web.httpContext.Current.

The code behind is in a class that inherits from the Page class that
provides you with the current HTTP context. Outside of such a page using
the property above allows to get access to the current request context...

Patrice
 
Is it that code-behind modules inherit Page? Is there more to it?

There is. The System.Web.UI.Page class is an HttpHandler; that is, it
implements the IHttpHandler Interface, because its purpose is to handle HTTP
Requests. The HttpHandler is given the entire context in which the HTTP
Request occurs (This is called the System.Web.HttpContext.Current object).
The HttpContext contains the Request, Response, Session, Application, and
other elements of the HttpContext of the current Request as Properties, in
order to respond. The HttpContext of the current Request is therefore, a
member by default of the Page class. In custom classes, you need to get a
handle on the Current HttpContext (which will only occur in the context of
an HttpRequest) in order to access these objects. This can be done by
referring to the System.Web.HttpContext.Current object. Once you've done
that, you can refer to the Application, for example, as
System.Web.HttpContext.Current.Application.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Back
Top