IHttpHandler.ProcessRequest メソッド
IHttpHandler インターフェイスを実装するカスタム HttpHandler によって、HTTP Web 要求の処理を有効にします。
Sub ProcessRequest( _
ByVal context As HttpContext _)
[C#]
void ProcessRequest(
HttpContextcontext);
[C++]
void ProcessRequest(
HttpContext* context);
[JScript]
function ProcessRequest(
context : HttpContext);
パラメータ
- context
HTTP 要求を処理するために使用する、組み込みのサーバー オブジェクト (Request 、 Response 、 Session 、 Server など) への参照を提供する HttpContext オブジェクト。
解説
カスタム HttpHandler コードを、次の例に示すように、 ProcessRequest 仮想メソッドに配置します。
使用例
handler.aspx という名前のページを求めるクライアント要求への応答として、4 行のテキストを HTTP 出力ストリームに書き込む例を次に示します。handler.aspx に対するすべての要求は、アセンブリ HandlerTest.dll に格納されている名前空間 HandlerExample の MyHttpHandler クラスによって処理されます。
' Name this Visual Basic file HandlerTest.vb and compile it with the
' command line: vbc /t:Library /r:System.Web.dll HandlerTest.vb.
' Copy HandlerTest.dll to your \bin directory.
Imports System.Web
Namespace HandlerExample
Public Class MyHttpHandler
Implements IHttpHandler
' Override the ProcessRequest method.
Public Sub ProcessRequest(context As HttpContext) _
Implements IHttpHandler.ProcessRequest
context.Response.Write("<H1>This is an HttpHandler Test.</H1>")
context.Response.Write("<p>Your Browser:</p>")
context.Response.Write("Type: " & context.Request.Browser.Type & "<br>")
context.Response.Write("Version: " & context.Request.Browser.Version)
End Sub
' Override the IsReusable property.
Public ReadOnly Property IsReusable() As Boolean _
Implements IHttpHandler.IsReusable
Get
Return True
End Get
End Property
End Class
End Namespace
'______________________________________________________________
'
' To use this handler, include the following lines in a
' Web.config file (be sure to remove the comment markers).
'
'<configuration>
' <system.web>
' <httpHandlers>
' <add verb="*" path="handler.aspx" type="HandlerTest.HandlerExample.MyHttpHandler,HandlerTest"/>
' </httpHandlers>
' </system.web>
'</configuration>
[C#]
// Name this C# file HandlerTest.cs and compile it with the
// command line: csc /t:Library /r:System.Web.dll HandlerTest.cs.
// Copy HandlerTest.dll to your \bin directory.
using System.Web;
namespace HandlerExample
{
public class MyHttpHandler : IHttpHandler
{
// Override the ProcessRequest method.
public void ProcessRequest(HttpContext context)
{
context.Response.Write("<H1>This is an HttpHandler Test.</H1>");
context.Response.Write("<p>Your Browser:</p>");
context.Response.Write("Type: " + context.Request.Browser.Type + "<br>");
context.Response.Write("Version: " + context.Request.Browser.Version);
}
// Override the IsReusable property.
public bool IsReusable
{
get { return true; }
}
}
}
/*
______________________________________________________________
To use this handler, include the following lines in a Web.config file.
<configuration>
<system.web>
<httpHandlers>
<add verb="*" path="handler.aspx" type="HandlerTest.HandlerExample.MyHttpHandler,HandlerTest"/>
</httpHandlers>
</system.web>
</configuration>
*/
[C++]
// Name this C++ file HandlerTest.cpp and compile it with the
// command line
// cl /clr /LD HandlerTest.cpp
// Copy HandlerTest.dll to your \bin directory.
using namespace System;
using namespace System::Web;
namespace HandlerExample
{
public __gc class MyHttpHandler : public IHttpHandler
{
// Override the ProcessRequest method.
public:
void ProcessRequest(HttpContext* context)
{
context->Response->Write(S"<H1>This is an HttpHandler Test.</H1>");
context->Response->Write(S"<p>Your Browser:</p>");
context->Response->Write(String::Format(S"Type: {0}<br>", context->Request->Browser->Type));
context->Response->Write(String::Format(S"Version: {0}", context->Request->Browser->Version));
}
// Override the IsReusable property.
__property bool get_IsReusable() { return true; }
};
}
/*
______________________________________________________________
To use this handler, include the following lines in a Web.config file.
<configuration>
<system.web>
<httpHandlers>
<add verb="*" path="handler.aspx" type="HandlerTest.HandlerExample.MyHttpHandler,HandlerTest"/>
</httpHandlers>
</system.web>
</configuration>
*/
[JScript]
// Name this JScript file handlertest.js and compile it with the
// command line: jsc /t:library /r:system.web.dll handlertest.js
// Copy HandlerTest.dll to your bin directory.
import System.Web
package HandlerExample{
class MyHttpHandler implements IHttpHandler{
// Override the ProcessRequest method.
function IHttpHandler.ProcessRequest(context : HttpContext){
context.Response.Write("<H1>This is an HttpHandler Test.</H1>")
context.Response.Write("<p>Your Browser:</p>")
context.Response.Write("Type: " + context.Request.Browser.Type + "<br>")
context.Response.Write("Version: " + context.Request.Browser.Version)
}
// Override the IsReusable property.
function get IHttpHandler.IsReusable() : Boolean{
return true
}
}
}
//______________________________________________________________
//
// To use the above handler, use the following lines in a
// Web.config file (remove the comment markers)
//
//<configuration>
// <system.web>
// <httpHandlers>
// <add verb="*" path="handler.aspx" type="HandlerTest.HandlerExample.MyHttpHandler,HandlerTest"/>
// </httpHandlers>
// </system.web>
//</configuration>
必要条件
プラットフォーム: Windows 2000, Windows XP Professional, Windows Server 2003 ファミリ