Export (0) Print
Expand All
Expand Minimize

Page.Context Property

Gets the HttpContext object associated with the page.

Namespace:  System.Web.UI
Assembly:  System.Web (in System.Web.dll)

'Declaration
Protected Friend Overrides ReadOnly Property Context As HttpContext

Property Value

Type: System.Web.HttpContext
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 HttpContext.AddError and HttpContext.ClearError methods and the 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.


Sub Page_Load(Sender As Object, e As EventArgs ) 

   Response.Write("<h3>Page.Context Example:</h3>")

   ' Add three custom exceptions.
  Context.AddError(New Exception( _
      "<h3 style=""color: red"">New Exception #1.</h3>"))
  Context.AddError(New Exception( _
      "<h3 style=""color: red"">New Exception #2.</h3>"))
  Context.AddError(New Exception( _
      "<h3 style=""color: red"">New Exception #3.</h3>"))

   ' Capture all the new Exceptions in an array.
   Dim errs() As Exception = Context.AllErrors
   Dim ex As Exception

   For Each ex In errs
      Response.Write("<p style='text-align:center; font-weight:bold'>")
      Response.Write(Server.HtmlEncode(ex.ToString()) + "</p>")
   Next

   ' Clear the exceptions so ASP.NET won't handle them.
   Context.ClearError()
End Sub

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 8.1, Windows Server 2012 R2, 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.

Show:
© 2014 Microsoft