IHttpHandler.IsReusable 属性

本文介绍了一个简单的C# HTTP处理器示例,演示了如何通过覆写ProcessRequest方法来响应HTTP请求,并展示如何设置IsReusable属性来指示处理器实例是否可被复用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 获取一个值,该值指示其他请求是否可以使用 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>
*/

 

[来源:MSDN]

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值