我有一个从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文件?请帮忙。
答案 0 :(得分:1)
您的配置不正确,您需要将类的名称空间添加到类型中,并声明处理程序dll,更改type
节点;
<configuration>
<system.web>
<system.webServer>
<handlers>
<add verb="*" path="*.abc" name="HelloWorldHandler"
type="HelloWorldHandler" />
</handlers>
</system.webServer>
</system.web>
</configuration>