ערוך

שתף באמצעות


DefaultHttpHandler Class

Definition

Represents the properties and methods of a default HTTP handler.

public ref class DefaultHttpHandler : System::Web::IHttpAsyncHandler
public class DefaultHttpHandler : System.Web.IHttpAsyncHandler
type DefaultHttpHandler = class
    interface IHttpAsyncHandler
    interface IHttpHandler
Public Class DefaultHttpHandler
Implements IHttpAsyncHandler
Inheritance
DefaultHttpHandler
Implements

Examples

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

public class AsyncDefaultHttpHandler : DefaultHttpHandler
{
    private HttpContext _context;

    public override IAsyncResult BeginProcessRequest(
      HttpContext context, AsyncCallback callback, object state)
    {
        AsyncResultSample ar = new AsyncResultSample(callback, state);
        _context = context;

        return ar;
    }

    public override void EndProcessRequest(IAsyncResult result)
    {
        _context.Response.Write("EndProcessRequest called.");
    }

    // This method should not be called asynchronously.
    public override void ProcessRequest(HttpContext context)
    {
        throw new InvalidOperationException(
                  "Asynchronous processing failed.");
    }

    // Enables pooling when set to true
    public override bool IsReusable
    {
        get { return true; }
    }
}

// Tracks state between the begin and end calls.
class AsyncResultSample : IAsyncResult
{
    private AsyncCallback callback = null;
    private Object asyncState;
    private Boolean isCompleted;

    internal AsyncResultSample(AsyncCallback cb, Object state)
    {
        this.callback = cb;
        asyncState = state;
        isCompleted = false;
    }

    public object AsyncState
    {
        get
        {
            return asyncState;
        }
    }

    public bool CompletedSynchronously
    {
        get
        {
            return false;
        }
    }

    public WaitHandle AsyncWaitHandle
    {
        get
        {
            throw new InvalidOperationException(
                      "ASP.NET should not use this property .");
        }
    }

    public bool IsCompleted
    {
        get
        {
            return isCompleted;
        }
    }

    internal void SetCompleted()
    {
        isCompleted = true;
        if (callback != null)
        {
            callback(this);
        }
    }
}
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
        Get
            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
        Get
            Return _asyncState
        End Get
    End Property

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

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

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

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

Remarks

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

Request interception can be set up through the wildcard application mapping feature introduced in IIS 6.0.

The DefaultHttpHandler class implements the IHttpAsyncHandler interface to provide asynchronous request processing. For general information about HTTP handlers, see HTTP Handlers and HTTP Modules Overview. Additionally, for more information see the following:

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.

Constructors

DefaultHttpHandler()

Initializes a new instance of the DefaultHttpHandler class.

Properties

Context

Gets the context that is associated with the current DefaultHttpHandler object.

ExecuteUrlHeaders

Gets a collection of request headers and request values to transfer along with the request.

IsReusable

Gets a Boolean value indicating that another request can use the current instance of the DefaultHttpHandler class.

Methods

BeginProcessRequest(HttpContext, AsyncCallback, Object)

Initiates an asynchronous call to the HTTP handler.

EndProcessRequest(IAsyncResult)

Provides an end method for an asynchronous process.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
OnExecuteUrlPreconditionFailure()

Called when preconditions prevent the DefaultHttpHandler object from processing a request.

OverrideExecuteUrlPath()

Overrides the target URL for the current request.

ProcessRequest(HttpContext)

Enables a DefaultHttpHandler object to process of HTTP Web requests.

ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to

See also