问题映射HttpHandler --> HTTP 错误 404 未找到
我在尝试在 web.config 中映射 HttpHandler 时遇到问题。
这是相关的配置位:
<httpHandlers>
<add verb="*" path="*.hndlr" type="MyAssembly.MyHandler, MyAssembly" validate="false" />
</httpHandlers>
当我导航到 http://localhost/myApp/whatever.hndlr 时,我收到服务器错误 404(未找到)。
这是我第一次连接 HttpHandler,所以我可能会丢失一些东西 - 感谢任何帮助!
更新:
到目前为止,我设法使用这两个答案使其正常工作 - 谁能够解释它为什么有效,就会得到答案标记!
这是我的配置(如果两者都没有,则不起作用 - 我在经典模式下运行IIS7)
System.web:
<httpHandlers>
<add verb="*" path="*MyHandler.hndlr" type="MyAssembly.MyAssemblyHandler, MyAssembly" validate="false"/>
</httpHandlers>
System.webserver:
<handlers>
<add name="MyHandler" verb="*" path="*MyHandler.hndlr" type="MyAssembly.MyAssemblyHandler, MyAssembly" validate="false" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script"/>
</handlers>
I am having problems trying to map an HttpHandler in the web.config.
This is the relevant config bit:
<httpHandlers>
<add verb="*" path="*.hndlr" type="MyAssembly.MyHandler, MyAssembly" validate="false" />
</httpHandlers>
When I navigate to http://localhost/myApp/whatever.hndlr
I am getting a server error 404 (not found).
It's the 1st time I am hooking up an HttpHandler so I might be missing something - any help appreciated!
UPDATE:
I managed to get it working using both answers so far - who's able to explain why it works gets the answer marked!
This is my config (won't work if you don't have both - I am running IIS7 in classic mode)
System.web:
<httpHandlers>
<add verb="*" path="*MyHandler.hndlr" type="MyAssembly.MyAssemblyHandler, MyAssembly" validate="false"/>
</httpHandlers>
System.webserver:
<handlers>
<add name="MyHandler" verb="*" path="*MyHandler.hndlr" type="MyAssembly.MyAssemblyHandler, MyAssembly" validate="false" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script"/>
</handlers>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
您是否使用 IIS7,如果是,应用程序池是否以经典模式或管道模式运行?如果是管道模式下的 IIS7,则处理程序引用需要进入下一节
而不是下一节。
Are you using IIS7, if so is the application pool running in classic or pipelined mode? If it is IIS7 in pipelined mode then the handler reference needs to go into the following section
rather than in the following section.
作为那些遇到这个问题的人的指南,我发现关键的属性是..
我最初按照微软的示例来设置它,他们的设置
一直给我404错误。我的 HTTPHandler 正在返回图形。
希望这有帮助:)
Just as a guide for those stuck with this problem I found the crucial attribute to be..
I originally followed a Microsoft example to set this up and they had it as
which just kept giving me 404 errors. My HTTPHandler is returning graphics.
Hope this helps :)
我使用的是IIS7,解决方案是:
在节
和节中
i am using IIS7, the solution is:
in section
and section
您的处理程序的扩展名是什么?如果您使用像 .hndlr 这样的自定义扩展,您可能还需要在 IIS 中添加 ScriptMap 并将其指向 ASP.NET 运行时,以便 IIS 可以转发请求到正确的处理器。
然后,在您的 web.config 中,您将需要在适当的部分中注册处理程序,如其他答案中所述。
What is the extension of your handler? If you are using a custom extension like .hndlr you may also need to add a ScriptMap in IIS and point it to the ASP.NET runtime so that IIS can forward the request to the correct processor.
Then in your web.config you will need to register the handler in the appropriate section as described in the other answer.
如果您已将处理程序设置为 32 位,但在 64 位中运行(反之亦然),也可能会遇到此错误。两者的设置都很简单,并且涵盖了所有基础。
注意“preCondition”和“scriptProcessor”的区别。
It is also possible to experience this error if you have set up the handler for 32 bit, but you are running in 64 bit (or vice versa). It's easy to set up both and have all the bases covered.
Note "preCondition", and "scriptProcessor" differences.
以前的答案都不适合我。
我正在使用
IIS 8.5、.Net v4.0、Integrated
,但使用以下处理程序配置时仍然收到 404:我启用了跟踪并发现了以下内容:
正如您所看到的,它看起来像是使用我的自定义 HttpHandler
testEmail
正确接收了请求,但是 MVC 窃取了它。我在
RouteConfig.cs
中打开路由定义,发现添加了:我让它忽略针对我的处理程序的请求。
希望这对某人有帮助 - 我正在撕扯我的头发!
None of the previous answers worked for me.
I'm using
IIS 8.5, .Net v4.0, Integrated
, and was still getting a 404 with the following handler config:I enabled tracing and found the following :
As you can see it looks like it had correctly picked up the request using my custom HttpHandler
testEmail
but MVC had stolen it.I opened my route definitions in
RouteConfig.cs
and found that adding:I got it to ignore requests meant for my Handler.
Hope this helps someone - I was tearing my hair out!
希望我的解决方案对其他人有帮助。在服务器从 IIS6 迁移到 7.5(两者都集成了 .Net 4.0)时,我有一个 Captcha 控件停止工作。事实证明,从
中的
解决了这个问题。
节点删除此属性preCondition="integratedMode,runtimeVersionv2.0"
;Hopefully my solution will help others. On a server move from IIS6 to 7.5, both .Net 4.0 Integrated, I had a Captcha control that quit working. It turns out that removing this attribute
preCondition="integratedMode,runtimeVersionv2.0"
from the<add>
node in<system.webserver><handlers>
resolved the issue.这似乎是一个边缘情况,但我有一个客户,我们的应用程序中使用的 httpHandler 无法在他们的任何服务器上工作。该处理程序指向一个 .ashx 页面,并从 JavaScript 调用它。
处理程序映射显示在 IIS 中,处理程序工厂也在那里,但当浏览器请求与处理程序关联的 ashx 页面时,我会收到 404。经过多次不同的修复尝试后,我们最终浏览到服务器上 IIS 中的文件,它特别显示了 404.7 与此消息一起返回。
•为 Web 服务器配置了请求过滤,并且此请求的文件扩展名被明确拒绝。
•验证 applicationhost.config 中的configuration/system.webServer/security/requestFiltering/fileExtensions 设置和web.config。
如果您收到此消息,则说明已在您的应用程序或网站级别为 .ashx 扩展名启用了请求过滤。转到站点和应用程序级别 IIS 中的“请求过滤”选项,并验证扩展程序未被阻止。有两种不同的方式可以配置请求过滤。
默认情况似乎是它仅显式阻止列表(黑名单)中配置的文件扩展名。另一种配置方式是,仅允许列表中专门配置的文件通过(白名单)。第二个选项是客户默认配置其所有 Windows 服务器的方式,结果发现 .ashx 文件扩展名不在允许的扩展名列表中。
This seems to be an edge case, but I had a customer where our httpHandler used in our application did not work on any of their servers. The handler pointed to an .ashx page and it was called from JavaScript.
The handler mapping showed up in IIS, the handler factory was there, but I would get a 404 when the browser requested the ashx page associated with the handler. After many different attempts to fix we finally browsed to the file in IIS on the server and it specifically showed a 404.7 being returned with this message.
•Request filtering is configured for the Web server and the file extension for this request is explicitly denied.
•Verify the configuration/system.webServer/security/requestFiltering/fileExtensions settings in applicationhost.config and web.config.
If you get this then Request Filtering is enabled for the .ashx extension at either your app or site level. Go to the Request Filtering option in IIS at both your site and app level and verify that the extension is not blocked. There are two different ways Request Filtering can be configured.
The default seems to be that it explicitly blocks only file extensions that are configured in the list (blacklist). The other way it can be configured is that only files specifically configured as allowed in the list are let through (whitelist). This second option is how the customer had configured all of their Windows Servers by default and it turns out that the .ashx file extension was not in the list of allowed extensions.
这是当我查找响应 404 的动词时出现的第一个线程。在我的例子中,解决方案是 VS 的配置
抱歉,我的 VS 是西班牙语
This is the first thread that appears when I look for a verb that responds with a 404. In my case the solution was a configuration of VS
Sorry, my VS is in spanish