当我将httpsndler编译成类时,我将dll放在哪里?

时间:2013-02-16 06:29:21

标签: c# asp.net

我有一个从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

enter image description here

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

enter image description here

1 个答案:

答案 0 :(得分:1)

您的配置不正确,您需要将类的名称空间添加到类型中,并声明处理程序dll,更改type节点;

<configuration>
  <system.web>        
<system.webServer>
    <handlers>
        <add verb="*" path="*.abc" name="HelloWorldHandler"
        type="HelloWorldHandler" />
    </handlers>
</system.webServer>
  </system.web>
</configuration>