Freigeben über


Page.Context-Eigenschaft

Ruft das der Seite zugeordnete HttpContext-Objekt ab.

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

Syntax

'Declaration
Protected Friend Overrides ReadOnly Property Context As HttpContext
'Usage
Dim value As HttpContext

value = Me.Context
protected internal override HttpContext Context { get; }
protected public:
virtual property HttpContext^ Context {
    HttpContext^ get () override;
}
/** @property */
protected HttpContext get_Context ()
protected internal override function get Context () : HttpContext

Eigenschaftenwert

Ein HttpContext-Objekt, das der aktuellen Seite zugeordnete Informationen enthält.

Hinweise

Diese Eigenschaft stellt programmgesteuerten Zugriff auf den Kontext bereit, in dem diese Seite ausgeführt wird. Dies schließt Informationen über Anforderung, Antwort, Sitzung und Anwendung ein.

Beispiel

Im folgenden Codebeispiel wird die Context-Eigenschaft für den Zugriff auf die HttpContext.AddError-Methode, HttpContext.ClearError-Methode und die HttpContext.AllErrors-Eigenschaft verwendet. Im Beispiel werden mithilfe der AddError-Methode drei benutzerdefinierte Ausnahmen erstellt und diese Ausnahmen mithilfe der AllErrors-Eigenschaft in ein Array geladen. Anschließend wird das Array in die Containerseite geschrieben, und mit der ClearError-Methode werden alle Fehler aus der Context-Eigenschaft gelöscht.

Sub Page_Load(Sender As Object, e As EventArgs ) 

   Response.Write("<h3>Page.Context Example:</h3>")
      
   ' Add three custom exceptions.
   Context.AddError(new Exception("<font color='red'><h3>New Exception #1.</h3>"))
   Context.AddError(new Exception("<font color='red'><h3>New Exception #2.</h3>"))
   Context.AddError(new Exception("<font color='red'><h3>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("<center><b>" + Server.HtmlEncode(ex.ToString()) + "</b></center><br>")
   Next
 
   ' Clear the exceptions so ASP.NET won't handle them.
   Context.ClearError()
End Sub
void Page_Load(Object sender,EventArgs e) 
{
   Response.Write("<h3>Page.Context Example:</h3>");

   // Add three custom exceptions.
   Context.AddError(new Exception("<font color='red'><h3>New Exception #1.</h3>"));
   Context.AddError(new Exception("<font color='red'><h3>New Exception #2.</h3>"));
   Context.AddError(new Exception("<font color='red'><h3>New Exception #3.</h3>"));
 
   // Capture all the new Exceptions in an array.
   Exception[] errs = Context.AllErrors;
 
   foreach (Exception ex in errs)
   {
      Response.Write("<center><b>" + Server.HtmlEncode(ex.ToString()) + "</b></center><br>"); 
   }
 
   // Clear the exceptions so ASP.NET won't handle them.
   Context.ClearError();
}
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
        ("<font color='red'><h3>New Exception #1.</h3>"));
    get_Context().AddError(new Exception
        ("<font color='red'><h3>New Exception #2.</h3>"));
    get_Context().AddError(new Exception
        ("<font color='red'><h3>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("<center><b>" 
            + get_Server().HtmlEncode(ex.ToString())
            +"</b></center><br>");
    }
    // Clear the exceptions so ASP.NET won't handle them.
    get_Context().ClearError();
}//Page_Load

Plattformen

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

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

Page-Klasse
Page-Member
System.Web.UI-Namespace
HttpContext