HttpHandler是asp.net真正处理Http请求的地方。在这个HttpHandler容器中,ASP.NET Framework才真正地对客户端请求的服务器页面做出编译和执行,并将处理过后的信息附加在HTTP请求信息流中再次返回到HttpModule中。


因为版本不同配置的节点位置有所不同

这是官方的配置节点

https://msdn.microsoft.com/zh-cn/library/7d6sws33(v=vs.80).aspx


在4.5版本的使用中发现

实际节点如下

<configuration>

  <system.webServer>
    <handlers>

<add name="prolist" verb="*" path="proinfo" type="mall.prolist,mall"/>

 </handlers>
   
  </system.webServer>

</configuration>

proinfo:是地址名称可以自定义配置

http://localhost:8361/prolist?pageindex=2&pagecount=1&queryparameters={%22proname%22:%22a%22}&Parametersign=360A9BA188A2B0E7217F018C4985E89B



一个简单的IHttpHandler

   

      第一:定义一个实现了IHttpHandler的类,并且实现其ProcessRequest方法。在一个HttpHandler容器中如果需要访问Session,必须实现IRequiresSessionState接口,这只是一个标记接口,没有任何方法。       

复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace MyHttpHandler
{
     public  class HelloHttpHandler:IHttpHandler
    {
         public  bool IsReusable 
        {
             get {  return  true; }
        }

         public  void ProcessRequest(HttpContext context) 
        {
            context.Response.Write( " HelloHttpHandler处理 ");
        }
    }
}

<add name="proinfo" verb="*" path="proinfo" type="MyHttpHandler. HelloHttpHandler,MyHttpHandler"/>
http://localhost:8361/proinfo
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐