7.4. Using the DefaultHttpHandler

The DefaultHttpHandler is a public class with a number of virtual methods that you can override. As a first step towards integrating ASP.NET authentication and authorization with classic ASP, you can create a custom HttpHandler that derives from DefaultHttpHandler:

C#

public class CustomHandler : DefaultHttpHandler
{
    public CustomHandler() {}

    public override string OverrideExecuteUrlPath()
    {
        //gets called just before control is handed back to IIS 6
        return null;
    }
public override void EndProcessRequest(IAsyncResult result)
 {
     //gets called when the original ISAPI extension is done processing
     //This step is useful for post-processing
     base.EndProcessRequest(result);
 }
}

VB.NET

Public Class CustomHandler
   Inherits DefaultHttpHandler

   Public Sub New()
   End Sub

   Public Overrides Function OverrideExecuteUrlPath() As String
         'gets called just before control is handed back to IIS 7.0
         Return Nothing
   End Function

   Public Overrides Sub EndProcessRequest(ByVal result As IAsyncResult)
         'gets called when the original ISAPI extension is done processing
         'This step is useful for post-processing
         MyBase.EndProcessRequest(result)
   End Sub
End Class

This code represents the basic skeleton of a custom HttpHandler. It overrides the two core methods available on DefaultHttpHandler: OverrideExecuteUrlPath and EndProcessRequest. You want to override the method OverrideExecuteUrlPath rather than the virtual BeginProcessRequest method for the following reasons:

  • Although you could ...

Get Professional ASP.NET 3.5 Security, Membership, and Role Management with C# and VB now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.