HttpContext.Current Tulajdonság
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Lekéri vagy beállítja az HttpContext aktuális HTTP-kérés objektumát.
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; }
static member Current : System.Web.HttpContext with get, set
Public Shared Property Current As HttpContext
Tulajdonság értéke
Az HttpContext aktuális HTTP-kérés példánya.
Példák
Az alábbi példakód a tulajdonságot használja a Current metódusokhoz és HttpContext.AddError a HttpContext.ClearErrorHttpContext.AllErrors tulajdonsághoz való hozzáféréshez. A példa három egyéni kivételt hoz létre a AddError metódus használatával, és a AllErrors tulajdonság használatával tölti be ezeket a kivételeket egy tömbbe. Ezután a tömböt a tartalmazó lapra írja, és a ClearError metódussal törli a tulajdonság összes hibáját Context .
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
Megjegyzések
Ez a tulajdonság az osztály statikus tulajdonsága HttpContext . A tulajdonság tárolja az HttpContext aktuális kérelemre vonatkozó példányt. A példány tulajdonságai az osztály nem statikus tulajdonságai HttpContext .
A tulajdonság használatával Page.Context az aktuális HTTP-kérés objektumához is hozzáférhet HttpContext .