Incapsula tutte le informazioni specifiche di HTTP relative a una singola richiesta HTTP.
System.Web.HttpContext
Spazio dei nomi: System.Web
Assembly: System.Web (in System.Web.dll)
Public NotInheritable Class HttpContext _ Implements IServiceProvider
public sealed class HttpContext : IServiceProvider
public ref class HttpContext sealed : IServiceProvider
[<Sealed>] type HttpContext = class interface IServiceProvider end
Il tipo HttpContext espone i seguenti membri.
| Nome | Descrizione | |
|---|---|---|
|
HttpContext(HttpWorkerRequest) | Consente di inizializzare una nuova istanza della classe HttpContext che utilizza l'oggetto richiesta di lavoro specificato. |
|
HttpContext(HttpRequest, HttpResponse) | Inizializza una nuova istanza della classe HttpContext utilizzando gli oggetti richiesta e risposta specificati. |
| Nome | Descrizione | |
|---|---|---|
|
AllErrors | Restituisce una matrice degli errori accumulati durante l'elaborazione di una richiesta HTTP. |
|
Application | Ottiene l'oggetto HttpApplicationState per la richiesta HTTP corrente. |
|
ApplicationInstance | Ottiene o imposta l'oggetto HttpApplication relativo alla richiesta HTTP corrente. |
|
Cache | Ottiene l'oggetto Cache per il dominio dell'applicazione corrente. |
|
Current | Ottiene o imposta l'oggetto HttpContext relativo alla richiesta HTTP corrente. |
|
CurrentHandler | Ottiene l'oggetto IHttpHandler che rappresenta il gestore attualmente in esecuzione. |
|
CurrentNotification | Ottiene un valore RequestNotification che indica l'evento HttpApplication attualmente in elaborazione. |
|
Error | Restituisce il primo errore, se presente, accumulato durante l'elaborazione di una richiesta HTTP. |
|
Handler | Ottiene o imposta l'oggetto IHttpHandler responsabile dell'elaborazione della richiesta HTTP. |
|
IsCustomErrorEnabled | Restituisce un valore che indica se gli errori personalizzati sono stati attivati per la richiesta HTTP corrente. |
|
IsDebuggingEnabled | Restituisce un valore che indica se la richiesta HTTP corrente è in modalità di debug. |
|
IsPostNotification | Ottiene un valore che indica se l'evento ASP.NET corrente è considerato un nuovo evento post. |
|
Items | Ottiene un insieme chiave/valore che è possibile utilizzare per organizzare e condividere dati tra un'interfaccia IHttpModule e un'interfaccia IHttpHandler durante una richiesta HTTP. |
|
PreviousHandler | Ottiene l'oggetto IHttpHandler relativo al gestore padre. |
|
Profile | Ottiene l'oggetto ProfileBase relativo al profilo utente corrente. |
|
Request | Restituisce l'oggetto HttpRequest relativo alla richiesta HTTP corrente. |
|
Response | Restituisce l'oggetto HttpResponse relativo alla risposta HTTP corrente. |
|
Server | Restituisce l'oggetto HttpServerUtility che fornisce i metodi da utilizzare nell'elaborazione delle richieste Web. |
|
Session | Restituisce l'oggetto HttpSessionState relativo alla richiesta HTTP corrente. |
|
SkipAuthorization | Ottiene o imposta un valore che specifica se l'oggetto UrlAuthorizationModule deve ignorare il controllo delle autorizzazioni per la richiesta corrente. |
|
Timestamp | Restituisce il formato data/ora iniziale della richiesta HTTP corrente. |
|
Trace | Restituisce l'oggetto TraceContext relativo alla risposta HTTP corrente. |
|
User | Ottiene o imposta le informazioni sulla sicurezza per la richiesta HTTP corrente. |
| Nome | Descrizione | |
|---|---|---|
|
AddError | Consente di aggiungere un'eccezione all'insieme delle eccezioni per la richiesta HTTP corrente. |
|
ClearError | Cancella tutti gli errori relativi alla richiesta HTTP corrente. |
|
Equals(Object) | Determina se l'oggetto Object specificato è uguale all'oggetto Object corrente. (Ereditato da Object) |
|
Finalize | Consente a un oggetto di provare a liberare risorse ed eseguire altre operazioni di pulitura prima che l'oggetto stesso venga recuperato dalla procedura di Garbage Collection. (Ereditato da Object) |
|
GetAppConfig | Obsoleta. Restituisce le informazioni sulla configurazione richieste per l'applicazione in uso. |
|
GetConfig | Obsoleta. Restituisce le informazioni sulla configurazione relative alla richiesta HTTP corrente |
|
GetGlobalResourceObject(String, String) | Ottiene un oggetto risorsa a livello di applicazione basato sulle proprietà ClassKey e ResourceKey specificate. |
|
GetGlobalResourceObject(String, String, CultureInfo) | Ottiene un oggetto risorsa a livello di applicazione basato sulle proprietà ClassKey e ResourceKey specificate e sull'oggetto CultureInfo. |
|
GetHashCode | Funge da funzione hash per un determinato tipo. (Ereditato da Object) |
|
GetLocalResourceObject(String, String) | Ottiene un oggetto risorsa a livello di pagina basato sulle proprietà VirtualPath e ResourceKey specificate. |
|
GetLocalResourceObject(String, String, CultureInfo) | Ottiene un oggetto risorsa a livello di pagina basato sulle proprietà VirtualPath e ResourceKey specificate e sull'oggetto CultureInfo. |
|
GetSection | Ottiene una sezione di configurazione specificata per la configurazione predefinita dell'applicazione corrente. |
|
GetType | Ottiene l'oggetto Type dell'istanza corrente. (Ereditato da Object) |
|
MemberwiseClone | Consente di creare una copia dei riferimenti dell'oggetto Object corrente. (Ereditato da Object) |
|
RemapHandler | Consente di specificare un gestore per la richiesta. |
|
RewritePath(String) | Riscrive l'URL utilizzando il percorso specificato. |
|
RewritePath(String, Boolean) | Riscrive l'URL utilizzando il percorso specificato e un valore booleano che specifica se il percorso virtuale per le risorse del server è stato modificato. |
|
RewritePath(String, String, String) | Riscrive l'URL utilizzando il percorso specificato, le informazioni sul percorso e le informazioni sulla stringa di query. |
|
RewritePath(String, String, String, Boolean) | Riscrive l'URL utilizzando il percorso virtuale specificato, informazioni sul percorso, informazioni della stringa di query e un valore booleano che specifica se il percorso del file del client è impostato sul percorso di riscrittura. |
|
SetSessionStateBehavior | Imposta il tipo di comportamento dello stato di sessione necessario per supportare una richiesta HTTP. |
|
ToString | Restituisce una stringa che rappresenta l'oggetto corrente. (Ereditato da Object) |
| Nome | Descrizione | |
|---|---|---|
|
IServiceProvider.GetService | Infrastruttura. Restituisce un oggetto per il tipo di servizio corrente. |
Alle classi che ereditano le interfacce IHttpModule e IHttpHandler viene fornito un riferimento a un oggetto HttpContext per la richiesta HTTP corrente. L'oggetto fornisce accesso alle proprietà intrinseche Request, Response e Server per la richiesta.
A complemento di questo argomento è disponibile un progetto di sito Web di Visual Studio con codice sorgente che è possibile scaricare.
Nell'esempio riportato di seguito viene illustrato come accedere alle proprietà dell'oggetto HttpContext e visualizzarle. È possibile accedere al contesto della richiesta HTTP corrente mediante la proprietà Context dell'oggetto Page.
<%@ Page Language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) ' The HttpContext associated with the page can be accessed by the Context property. Dim sb As New System.Text.StringBuilder() ' Use the current HttpContext object to determine if custom errors are enabled. sb.Append("Is custom errors enabled: " & _ Context.IsCustomErrorEnabled.ToString() & "<br/>") ' Use the current HttpContext object to determine if debugging is enabled. sb.Append("Is debugging enabled: " & _ Context.IsDebuggingEnabled.ToString() & "<br/>") ' Use the current HttpContext object to access the current TraceContext object. sb.Append("Trace Enabled: " & _ Context.Trace.IsEnabled.ToString() & "<br/>") ' Use the current HttpContext object to access the current HttpApplicationState object. sb.Append("Number of items in Application state: " & _ Context.Application.Count.ToString() & "<br/>") ' Use the current HttpContext object to access the current HttpSessionState object. ' Session state may not be configured. Try sb.Append("Number of items in Session state: " & _ Context.Session.Count.ToString() & "<br/>") Catch ex As Exception sb.Append("Session state not enabled. <br/>") End Try ' Use the current HttpContext object to access the current Cache object. sb.Append("Number of items in the cache: " & _ Context.Cache.Count.ToString() & "<br/>") ' Use the current HttpContext object to determine the timestamp for the current HTTP Request. sb.Append("Timestamp for the HTTP request: " & _ Context.Timestamp.ToString() & "<br/>") ' Assign StringBuilder object to output label. OutputLabel.Text = sb.ToString() End Sub </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>HttpContext Example</title> </head> <body> <form id="form1" runat="server"> <div> Using the current HttpContext to get information about the current page. <br /> <asp:Label id="OutputLabel" runat="server"></asp:Label> </div> </form> </body> </html>
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { // The HttpContext associated with the page can be accessed by the Context property. System.Text.StringBuilder sb = new System.Text.StringBuilder(); // Use the current HttpContext object to determine if custom errors are enabled. sb.Append("Is custom errors enabled: " + Context.IsCustomErrorEnabled.ToString() + "<br/>"); // Use the current HttpContext object to determine if debugging is enabled. sb.Append("Is debugging enabled: " + Context.IsDebuggingEnabled.ToString() + "<br/>"); // Use the current HttpContext object to access the current TraceContext object. sb.Append("Trace Enabled: " + Context.Trace.IsEnabled.ToString() + "<br/>"); // Use the current HttpContext object to access the current HttpApplicationState object. sb.Append("Number of items in Application state: " + Context.Application.Count.ToString() + "<br/>"); // Use the current HttpContext object to access the current HttpSessionState object. // Session state may not be configured. try { sb.Append("Number of items in Session state: " + Context.Session.Count.ToString() + "<br/>"); } catch { sb.Append("Session state not enabled. <br/>"); } // Use the current HttpContext object to access the current Cache object. sb.Append("Number of items in the cache: " + Context.Cache.Count.ToString() + "<br/>"); // Use the current HttpContext object to determine the timestamp for the current HTTP Request. sb.Append("Timestamp for the HTTP request: " + Context.Timestamp.ToString() + "<br/>"); // Assign StringBuilder object to output label. OutputLabel.Text = sb.ToString(); } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>HttpContext Example</title> </head> <body> <form id="form1" runat="server"> <div> Using the current HttpContext to get information about the current page. <br /> <asp:Label id="OutputLabel" runat="server"></asp:Label> </div> </form> </body> </html>
.NET Framework
Supportato in: 4, 3.5, 3.0, 2.0, 1.1, 1.0Windows 7, Windows Vista SP1 o versione successiva, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (componenti di base del server non supportati), Windows Server 2008 R2 (componenti di base del server supportati con SP1 o versione successiva), Windows Server 2003 SP2
.NET Framework non supporta tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema di .NET Framework.