DefaultHttpHandler 类

定义

表示默认 HTTP 处理程序的属性和方法。

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
继承
DefaultHttpHandler
实现

示例

下面的代码示例演示如何通过派生自 DefaultHttpHandler 类来实现自定义 HTTP 处理程序。

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

注解

DefaultHttpHandler如果通过 Internet Information Services (IIS) 6.0 配置了两个请求拦截,并且没有显式绑定应用于所请求的扩展,则对象将截获 HTTP 管道中的传入请求。

可以通过 IIS 6.0 中引入的通配符应用程序映射功能设置请求拦截。

DefaultHttpHandler 实现 IHttpAsyncHandler 接口以提供异步请求处理。 有关 HTTP 处理程序的一般信息,请参阅 HTTP 处理程序和 HTTP 模块概述。 此外,有关详细信息,请参阅以下内容:

类可以从 类派生 DefaultHttpHandler ,以提供对请求的自定义处理。 派生自 DefaultHttpHandler 的异步 HTTP 处理程序可以重写 方法, BeginProcessRequest 以更改处理请求的方式。

DefaultHttpHandler不使用 ASP.NET 错误。 使用 IIS 错误或正当 ISAPI 自定义错误机制的现有内容将保持不变。

构造函数

DefaultHttpHandler()

初始化 DefaultHttpHandler 类的新实例。

属性

Context

获取与当前 DefaultHttpHandler 对象关联的上下文。

ExecuteUrlHeaders

获取要随请求一起传输的请求标头和请求值的集合。

IsReusable

获取一个布尔值,该值指示另一个请求可以使用 DefaultHttpHandler 类的当前实例。

方法

BeginProcessRequest(HttpContext, AsyncCallback, Object)

启动对 HTTP 处理程序的异步调用。

EndProcessRequest(IAsyncResult)

为异步进程提供一种结束方法。

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
OnExecuteUrlPreconditionFailure()

在前提条件阻止 DefaultHttpHandler 对象处理请求时被调用。

OverrideExecuteUrlPath()

重写当前请求的目标 URL。

ProcessRequest(HttpContext)

使 DefaultHttpHandler 对象能够处理 HTTP Web 请求。

ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于

另请参阅