DefaultHttpHandler Classe

Definizione

Rappresenta le proprietà e i metodi di un gestore HTTP predefinito.

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
Ereditarietà
DefaultHttpHandler
Implementazioni

Esempio

Nell'esempio di codice seguente viene illustrato come implementare un gestore HTTP personalizzato derivando dalla DefaultHttpHandler classe .

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

Commenti

Un DefaultHttpHandler oggetto intercetta le richieste in ingresso nella pipeline HTTP quando entrambe le intercettazioni richieste sono state configurate tramite Internet Information Services (IIS) 6.0 e nessuna associazione esplicita si applica all'estensione richiesta.

L'intercettazione delle richieste può essere configurata tramite la funzionalità di mapping delle applicazioni con caratteri jolly introdotta in IIS 6.0.

La DefaultHttpHandler classe implementa l'interfaccia per fornire l'elaborazione IHttpAsyncHandler asincrona delle richieste. Per informazioni generali sui gestori HTTP, vedere Cenni preliminari sui gestori HTTP e sui moduli HTTP. Per altre informazioni, vedere anche:

Le classi possono derivare dalla DefaultHttpHandler classe per fornire una gestione personalizzata delle richieste. Un gestore HTTP asincrono derivato da potrebbe eseguire l'override DefaultHttpHandler del metodo per modificare la BeginProcessRequest modalità di elaborazione delle richieste.

Un DefaultHttpHandler oggetto non utilizza errori ASP.NET. Il contenuto esistente che usa errori IIS o un meccanismo di errore personalizzato ISAPI proprietario funzionerebbe invariato.

Costruttori

DefaultHttpHandler()

Inizializza una nuova istanza della classe DefaultHttpHandler.

Proprietà

Context

Ottiene il contesto associato all'oggetto DefaultHttpHandler corrente.

ExecuteUrlHeaders

Ottiene un insieme delle intestazioni e dei valori della richiesta da trasferire insieme alla richiesta.

IsReusable

Ottiene un valore booleano che indica che l'istanza corrente della classe DefaultHttpHandler può essere utilizzata da un'altra richiesta.

Metodi

BeginProcessRequest(HttpContext, AsyncCallback, Object)

Avvia una chiamata asincrona al gestore HTTP.

EndProcessRequest(IAsyncResult)

Fornisce un metodo di fine per un processo asincrono.

Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.

(Ereditato da Object)
GetHashCode()

Funge da funzione hash predefinita.

(Ereditato da Object)
GetType()

Ottiene l'oggetto Type dell'istanza corrente.

(Ereditato da Object)
MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.

(Ereditato da Object)
OnExecuteUrlPreconditionFailure()

Viene chiamato quando le precondizioni impediscono l'elaborazione di una richiesta da parte dell'oggetto DefaultHttpHandler.

OverrideExecuteUrlPath()

Esegue l'override dell'URL di destinazione per la richiesta corrente.

ProcessRequest(HttpContext)

Consente a un oggetto DefaultHttpHandler di elaborare le richieste Web HTTP Web.

ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Si applica a

Vedi anche