IHttpHandler.ProcessRequest(HttpContext) Método

Definición

Permite el procesamiento de solicitudes Web HTTP mediante un HttpHandler personalizado que implementa la interfaz IHttpHandler.

public:
 void ProcessRequest(System::Web::HttpContext ^ context);
public void ProcessRequest (System.Web.HttpContext context);
abstract member ProcessRequest : System.Web.HttpContext -> unit
Public Sub ProcessRequest (context As HttpContext)

Parámetros

context
HttpContext

Objeto HttpContext que proporciona referencias a los objetos de servidor intrínsecos (por ejemplo, Request, Response, Session y Server) utilizados para atender las solicitudes HTTP.

Ejemplos

En el ejemplo de código siguiente se escriben cuatro líneas de texto en el flujo de salida HTTP en respuesta a una solicitud de cliente para una página denominada handler.aspx. Todas las solicitudes de handler.aspx son administradas por la MyHttpHandler clase del espacio de nombres HandlerExample incluido en el ensamblado HandlerTest.dll.

// Name this C# file HandlerTest.cs and compile it with the
// command line: csc /t:library /r:System.Web.dll HandlerTest.cs.
// Copy HandlerTest.dll to your \bin directory.

using System.Web;

namespace HandlerExample
{
   public class MyHttpHandler : IHttpHandler
   {
      // Override the ProcessRequest method.
      public void ProcessRequest(HttpContext context)
      {
         context.Response.Write("<H1>This is an HttpHandler Test.</H1>");
         context.Response.Write("<p>Your Browser:</p>");
         context.Response.Write("Type: " + context.Request.Browser.Type + "<br>");
         context.Response.Write("Version: " + context.Request.Browser.Version);
      }

      // Override the IsReusable property.
      public bool IsReusable
      {
         get { return true; }
      }
   }
}

/*
______________________________________________________________

To use this handler, include the following lines in a Web.config file.

<configuration>
   <system.web>
      <httpHandlers>
         <add verb="*" path="handler.aspx" type="HandlerExample.MyHttpHandler,HandlerTest"/>
      </httpHandlers>
   </system.web>
</configuration>
*/
' Name this Visual Basic file HandlerTest.vb and compile it with the
' command line: vbc /target:library /r:System.Web.dll HandlerTest.vb.
' Copy HandlerTest.dll to your \bin directory.
Imports System.Web

Namespace HandlerExample
    
    Public Class MyHttpHandler
        Implements IHttpHandler
        
        ' Override the ProcessRequest method.
        Public Sub ProcessRequest(context As HttpContext) _
        Implements IHttpHandler.ProcessRequest
        
            context.Response.Write("<H1>This is an HttpHandler Test.</H1>")
            context.Response.Write("<p>Your Browser:</p>")
            context.Response.Write("Type: " & context.Request.Browser.Type & "<br>")
            context.Response.Write("Version: " & context.Request.Browser.Version)
        End Sub
        
        ' Override the IsReusable property.        
        Public ReadOnly Property IsReusable() As Boolean _
        Implements IHttpHandler.IsReusable
        
            Get
                Return True
            End Get
        End Property
    End Class
End Namespace

'______________________________________________________________
'
' To use this handler, include the following lines in a
' Web.config file (be sure to remove the comment markers).
'
'         <add verb="*" path="handler.aspx" type="HandlerExample.MyHttpHandler,HandlerTest"/>

Comentarios

Coloque el código personalizado HttpHandler en el ProcessRequest método virtual, como se muestra en la sección Ejemplos.

Se aplica a