DefaultHttpHandler Class

Note: This class is new in the .NET Framework version 2.0.

Represents the properties and methods of a default HTTP handler.

Namespace: System.Web
Assembly: System.Web (in system.web.dll)

Public Class DefaultHttpHandler
	Implements IHttpAsyncHandler, IHttpHandler
Dim instance As DefaultHttpHandler

public class DefaultHttpHandler implements IHttpAsyncHandler, IHttpHandler
public class DefaultHttpHandler implements IHttpAsyncHandler, IHttpHandler

A DefaultHttpHandler object intercepts incoming requests in the HTTP pipeline when both request interception has been configured through Microsoft Internet Information Services (IIS) version 6.0 and no explicit httpHandlers bindings apply to the requested extension.

Request interception can be set up through the wildcard application mapping feature introduced in IIS 6.0. For more information, search the MSDN Library for information about using wildcard application maps to remap a URL.

The DefaultHttpHandler class implements the IHttpAsyncHandler interface to provide asynchronous request processing. For general information about HTTP handlers, see Custom ASP.NET Processing with HTTP Handlers. Additionally, for more information:

Classes can derive from the DefaultHttpHandler class to provide customized handling of requests. An asynchronous HTTP handler that is derived from the DefaultHttpHandler could override the BeginProcessRequest method to change how requests are processed.

A DefaultHttpHandler does not use ASP.NET errors. Existing content that uses IIS errors or a propriety ISAPI custom error mechanism would work unchanged.

The following code example demonstrates how to implement a customized HTTP handler by deriving from the DefaultHttpHandler class.

Public Class defaulthttpexampleVB
    Inherits DefaultHttpHandler

    Private _context As HttpContext

    Public Overrides Function BeginProcessRequest _
        (ByVal context As HttpContext, _
         ByVal callback As AsyncCallback, _
         ByVal state As Object) As IAsyncResult

        Dim ar As New AsyncResultSample(callback, state)
        _context = context

        Return (ar)
    End Function

    Public Overrides Sub EndProcessRequest(ByVal result As IAsyncResult)
        _context.Response.Write("EndProcessRequest called.")
    End Sub

    ' This method should not be called asynchronously.
    Public Overrides Sub ProcessRequest(ByVal context As HttpContext)
        Throw New InvalidOperationException _
          ("Asynchronous processing failed.")
    End Sub

    ' Enables pooling when set to true
    Public Overrides ReadOnly Property IsReusable() As Boolean
            Return True
        End Get
    End Property
End Class

' Tracks state between the begin and end calls.
Class AsyncResultSample
    Implements IAsyncResult
    Private callback As AsyncCallback = Nothing
    Private _asyncState As Object
    Private _isCompleted As Boolean

    Friend Sub New(ByVal cb As AsyncCallback, ByVal state As Object)
        Me.callback = cb
        _asyncState = state
        _isCompleted = False
    End Sub

    Public ReadOnly Property AsyncState() As Object _
      Implements IAsyncResult.AsyncState
            Return _asyncState
        End Get
    End Property

    Public ReadOnly Property CompletedSynchronously() _
      As Boolean Implements IAsyncResult.CompletedSynchronously
            Return False
        End Get
    End Property

    Public ReadOnly Property AsyncWaitHandle() _
      As WaitHandle Implements IAsyncResult.AsyncWaitHandle
            Throw New InvalidOperationException _
              ("ASP.NET should not use this property .")
        End Get
    End Property

    Public ReadOnly Property IsCompleted() _
      As Boolean Implements IAsyncResult.IsCompleted
            Return IsCompleted
        End Get
    End Property

    Friend Sub SetCompleted()
        _isCompleted = True
        If (callback <> Nothing) Then
        End If
    End Sub
End Class

  • AspNetHostingPermission  for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
  • AspNetHostingPermission  for operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0