Export (0) Print
Expand All
0 out of 7 rated this helpful - Rate this topic

Page.Context Property

Gets the HttpContext object associated with the page.

Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)
protected public:
virtual property HttpContext^ Context {
	HttpContext^ get () override;
/** @property */
protected HttpContext get_Context ()

protected internal override function get Context () : HttpContext

Not applicable.

Property Value

An HttpContext object that contains information associated with the current page.

This property provides programmatic access to the context the page runs in, including information about the request, response, session, and application.

The following code example uses the Context property to access the System.Web.HttpContext.AddError(System.Exception) and System.Web.HttpContext.ClearError methods and the System.Web.HttpContext.AllErrors property. The example creates three custom exceptions using the AddError method and uses the AllErrors property to load these exceptions to an array. It then writes the array to the containing page and uses the ClearError method to clear all the errors from the Context property.

No code example is currently available or this language may not be supported.
void Page_Load(Object sender,System.EventArgs e) 
    get_Response().Write("<h3>Page.Context Example:</h3>");

    // Add three custom exceptions.
    get_Context().AddError(new Exception
        ("<h3 style=\"color: red\">New Exception #1.</h3>"));
    get_Context().AddError(new Exception
        ("<h3 style=\"color: red\">New Exception #2.</h3>"));
    get_Context().AddError(new Exception
        ("<h3 style=\"color: red\">New Exception #3.</h3>"));
    // Capture all the new Exceptions in an array.
    System.Exception errs[] = get_Context().get_AllErrors();
    for (int iCtr=0;iCtr<errs.length;iCtr++) 
        System.Exception ex = errs[iCtr];
        get_Response().Write("<p style='text-align: center; " 
            + "font-weight: bold'>"
            + get_Server().HtmlEncode(ex.ToString())
            + "</p>");
    // Clear the exceptions so ASP.NET won't handle them.

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft. All rights reserved.