获取一个值,该值指示其他请求是否可以使用 IHttpHandler 实例。
//
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 in 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="HandlerExample.MyHttpHandler,HandlerTest"/>
</httpHandlers>
</system.web>
</configuration>
*/
本文介绍了一个简单的C# HTTP处理器示例,演示了如何通过覆写ProcessRequest方法来响应HTTP请求,并展示如何设置IsReusable属性来指示处理器实例是否可被复用。
957

被折叠的 条评论
为什么被折叠?



