创建我的第一个HttpHandler -不工作
本文关键字:工作 HttpHandler 我的 第一个 创建 | 更新日期: 2023-09-27 18:06:09
我希望有一个简单的解决方案。我使用MVC 3。我的解决方案中有两个项目,一个名为MyApp的类库。域,以及名为myapp .Web的MVC 3 Web应用程序。
在MyApp。域,我有这个文件:
namespace MyApp.Domain.Test
{
public class MyHandler : IHttpHandler
{
public bool IsReusable
{
get { return false; }
}
public void ProcessRequest(HttpContext context)
{
context.Response.Write("test");
}
}
}
在MyApp 。web,在web中。在项目的根目录下配置,我有这样的:
<configuration>
<system.web>
<httpHandlers>
<add verb="*" path="*.testhandler" type="MyApp.Domain.Test.MyHandler"/>
</httpHandlers>
</system.web>
</configuration>
但是,如果我导航到http://localhost:52233/test.testhandler,我得到一个404错误。我想这里有某种命名空间问题,但我不知道如何修复它。
有人遇到过这个问题吗?
尝试忽略路由中的URL模式。在global.asax:
的默认路由之前添加这个routes.IgnoreRoute("{resource}.testhandler/{*pathInfo}");
我认为问题是IIS没有将您的请求路由到您的应用程序。只有某些已定义的文件扩展名(如.aspx或.ashx)在IIS中注册以路由到ASP。网络应用程序。如果你改变你的网。配置行到
<add verb="*" path="testhandler.ashx" type="MyApp.Domain.Test.MyHandler,MyAssembly"/>
和您对
的请求http://localhost: 52233/testhandler.ashx
你可能会更成功。请注意,我已经将程序集名称添加到'type'值中-我认为这也是必需的。