asp.net.ph

IHttpHandler.ProcessRequest Method

System.Web Namespace   IHttpHandler Interface


Enables processing of HTTP Web requests by a custom HttpHandler that implements the IHttpHandler interface.

[ VB ]
Sub ProcessRequest ( _
   ByVal context As HttpContext _
)

[ C# ]
void ProcessRequest (
   HttpContext context
);

[ C++ ]
void ProcessRequest (
   HttpContext* context
);

[ JScript ]
function ProcessRequest (
   context : HttpContext
);

Parameters

context
An HttpContext object that provides references to the intrinsic server objects ( for example, Request, Response, Session, and Server ) used to service HTTP requests.

Remarks

Place your custom HttpHandler code in the ProcessRequest virtual method as shown in the following example.

Example

The following example writes four lines of text to the HTTP output stream in response to a client request for a page named handler.aspx. All requests for handler.aspx are serviced by the myHttpHandler class in the namespace HandlerExample contained in the assembly HandlerTest.dll.

[ VB ] 
' Name this Visual Basic file HandlerTest.vb and compile it with the
' command line: vbc /t: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


[ C# ] 
// 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 the above handler, add the following lines to the Web.config file.

<configuration>
   <system.web>
      <httpHandlers>
         <add verb="*"
            path="handler.aspx"
            type="HandlerExample.myHttpHandler,HandlerTest"/>
      </httpHandlers>
   </system.web>
</configuration>
See Also

IHttpHandler Members Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph