共用方式為


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 處理常式的非同步呼叫 (Asynchronous Call)。

EndProcessRequest(IAsyncResult)

提供非同步處理序的結束方法。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
OnExecuteUrlPreconditionFailure()

當先決條件防止 DefaultHttpHandler 物件處理要求時呼叫。

OverrideExecuteUrlPath()

覆寫目前要求的目標 URL。

ProcessRequest(HttpContext)

DefaultHttpHandler 物件可以處理 HTTP Web 要求。

ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於

另請參閱