0

我有一个从 msdn 获得的 httphandler,看起来像这样

using System.Web;
public class HelloWorldHandler : IHttpHandler
{
    public HelloWorldHandler()
    {
    }
    public void ProcessRequest(HttpContext context)
    {
        HttpRequest Request = context.Request;
        HttpResponse Response = context.Response;
        // This handler is called whenever a file ending 
        // in .sample is requested. A file with that extension
        // does not need to exist.
        Response.Write("hello"); 


    }
    public bool IsReusable
    {
        // To enable pooling, return true here.
        // This keeps the handler in memory.
        get { return false; }
    }
}

所以我Handler.dll将它编译并放入C:\inetpub\wwwroot\Handler

然后我添加了这个 Web.config 文件

<configuration>
  <system.web>
    <httpHandlers>
      <add verb="*" path="*.abc" 
        type="HelloWorldHandler", "HelloWorldHandler" />
    </httpHandlers>
  </system.web>
</configuration>

并把它C:\inetpub\wwwroot\Handler也放进去

在此处输入图像描述

我想用这个然后我可以去http://localhost/Handler/page.abc处理程序会拦截请求,但这不是这样吗?我怀疑它可能是 .config 文件?请帮忙。

在此处输入图像描述

4

1 回答 1

1

你的配置不对,需要在类型中添加类的命名空间,还要声明handler dll,更改type节点;

<configuration>
  <system.web>        
<system.webServer>
    <handlers>
        <add verb="*" path="*.abc" name="HelloWorldHandler"
        type="HelloWorldHandler" />
    </handlers>
</system.webServer>
  </system.web>
</configuration>
于 2013-02-16T06:37:04.903 回答