HttpContext.Current Propiedad

Definición

Obtiene o establece el objeto HttpContext de la solicitud HTTP actual.

public:
 static property System::Web::HttpContext ^ Current { System::Web::HttpContext ^ get(); void set(System::Web::HttpContext ^ value); };
public static System.Web.HttpContext Current { get; set; }
member this.Current : System.Web.HttpContext with get, set
Public Shared Property Current As HttpContext

Valor de propiedad

HttpContext

Instancia de HttpContext de la solicitud HTTP actual.

Ejemplos

En el ejemplo de código siguiente se usa la Current propiedad para tener acceso a los HttpContext.AddError métodos y HttpContext.ClearError y a la HttpContext.AllErrors propiedad . En el ejemplo se crean tres excepciones personalizadas mediante el AddError método y se usa la AllErrors propiedad para cargar estas excepciones en una matriz. A continuación, escribe la matriz en la página contenedora y usa el ClearError método para borrar todos los errores de la Context propiedad .

protected void Page_Load(object sender, EventArgs e)
{
    HttpContext context = HttpContext.Current;
    Response.Write("<p>HttpContext.Current Example:</p>");

    // Add three custom exceptions.
    context.AddError(new Exception("New Exception #1"));
    context.AddError(new Exception("New Exception #2"));
    context.AddError(new Exception("New Exception #3"));

    // Capture all the new Exceptions in an array.
    Exception[] errs = context.AllErrors;

    foreach (Exception ex in errs)
    {
        Response.Write("<p>" + Server.HtmlEncode(ex.ToString()) + "</p>");
    }

    // Clear the exceptions so ASP.NET won't handle them.
    context.ClearError();
}
Protected Sub Page_Load(sender As Object, e As EventArgs)
Dim context As HttpContext = HttpContext.Current
Response.Write("<p>HttpContext.Current Example:</p>")

' Add three custom exceptions.
context.AddError(New Exception("New Exception #1"))
context.AddError(New Exception("New Exception #2"))
context.AddError(New Exception("New Exception #3"))

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

For Each ex As Exception In errs
Response.Write("<p>" & Server.HtmlEncode(ex.ToString()) & "</p>")
Next

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

Comentarios

Esta propiedad es una propiedad estática de la HttpContext clase . La propiedad almacena la HttpContext instancia que se aplica a la solicitud actual. Las propiedades de esta instancia son las propiedades no estáticas de la HttpContext clase .

También puede usar la Page.Context propiedad para tener acceso al HttpContext objeto de la solicitud HTTP actual.

Se aplica a

Consulte también