Cliquez pour évaluer et commenter
MSDN
MSDN Library
Développement .NET
.NET Framework 3.5
.NET Framework
Bibliothèque de classes ....
System.Web, espace de noms
HttpContext, classe

  Passer à l'affichage pour faible bande passante
Cette page est spécifique à
Microsoft Visual Studio 2008/.NET Framework 3.5

D'autres versions sont également disponibles pour :
Bibliothèque de classes .NET Framework
HttpContext, classe

Mise à jour : novembre 2007

Encapsule toutes les informations spécifiques au protocole HTTP sur une requête HTTP individuelle.

Espace de noms :  System.Web
Assembly :  System.Web (dans System.Web.dll)

Visual Basic (Déclaration)
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class HttpContext _
    Implements IServiceProvider
Visual Basic (Utilisation)
Dim instance As HttpContext
C#
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class HttpContext : IServiceProvider
VisualC++
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class HttpContext sealed : IServiceProvider
J#
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal) */
public final class HttpContext implements IServiceProvider
JScript
public final class HttpContext implements IServiceProvider

Les classes qui héritent des interfaces IHttpModule et IHttpHandler reçoivent une référence à un objet HttpContext pour la requête HTTP actuelle. L'objet fournit l'accès aux propriétés Request, Response et Server pour la requête.

HttpContext est introduit dans le .NET Framework version 3.5. Pour plus d'informations, consultez la page Architecture de .NET Framework 3.5.

TopicLocation
Comment : créer un gestionnaire HTTP asynchroneGénération d'applications Web ASP.NET
Comment : créer un gestionnaire HTTP asynchroneGénération d'applications Web ASP.NET dans Visual Studio
Développement de contrôles liés aux données personnalisés pour ASP.NET 1.1Création de contrôles ASP.NET
Développement de contrôles liés aux données personnalisés pour ASP.NET 1.1Génération d'applications Web ASP.NET dans Visual Studio
Développement de contrôles liés aux données personnalisés pour ASP.NET 2.0Création de contrôles ASP.NET
Développement de contrôles liés aux données personnalisés pour ASP.NET 2.0 ou version ultérieureGénération d'applications Web ASP.NET dans Visual Studio
Procédure pas à pas : création d'un contrôle Web ASP.NET lié aux données personnalisé pour ASP.NET 1.1Création de contrôles ASP.NET
Procédure pas à pas : création d'un contrôle Web ASP.NET lié aux données personnalisé pour ASP.NET 1.1Génération d'applications Web ASP.NET dans Visual Studio
Procédure pas à pas : création d'un contrôle Web ASP.NET lié aux données personnalisé pour ASP.NET 2.0Création de contrôles ASP.NET
Procédure pas à pas : création d'un contrôle Web ASP.NET lié aux données personnalisé pour ASP.NET 2.0Génération d'applications Web ASP.NET dans Visual Studio
Procédure pas à pas : développement et utilisation d'un contrôle serveur personnaliséCréation de contrôles ASP.NET
Procédure pas à pas : développement et utilisation d'un contrôle serveur personnaliséGénération d'applications à l'aide de Visual Web Developer

L'exemple de code suivant montre comment accéder aux propriétés de l'objet HttpContext et les afficher. Le contexte de la requête HTTP actuelle est accessible via la propriété Context de l'objet Page.

Visual Basic
<%@ 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  >
<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>

C#
<%@ 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  >
<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>

System..::.Object
  System.Web..::.HttpContext
Tous les membres static (Shared en Visual Basic) publics de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professionnel Édition x64, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

Le .NET Framework et le .NET Compact Framework ne prennent pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.

.NET Framework

Pris en charge dans : 3.5, 3.0, 2.0, 1.1, 1.0
Contenu de la communauté   Qu'est-ce que le Contenu de la communauté ?
Ajouter du contenu RSS  Annotations
Processing
© 2009 Microsoft Corporation. Tous droits réservés. Conditions d'utilisation  |  Marques  |  Confidentialité
Page view tracker