当资源丢失时,EndRequest 不会在 IIS 上触发

发布于 2024-08-19 19:15:48 字数 212 浏览 4 评论 0原文

我有一个 HttpModule,它挂接到 IIS6 上的 EndRequest 事件,并注册了通配符处理程序,只要请求在 .aspx 页面上结束,它就可以正常工作,但如果 url 丢失 (404),则无法正常工作。

我猜这是因为 staticfilehandler 结束了请求,但是这个问题有什么好的解决方案吗?

我在 IIS7(管道模式)中尝试了相同的解决方案,并且工作正常。

I have a HttpModule that hooks on to the EndRequest Event on a IIS6 with a wildcard handler registered and it works fine as long as the request ends on a .aspx page, but NOT if the url is missing (404).

I guess it's because of the staticfilehandler ends the request, but is there any good solution for this problem ?

I have tried the same solution in IIS7 (pipeline mode) and there it works fine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空城旧梦 2024-08-26 19:15:48

我要尝试的第一件事是告诉 IIS 不要验证文件是否存在,这将允许请求传递到 HttpModule。您可以对任何特定文件映射(包括通配符)执行此操作。

如果上述方法不可行,更糟糕的情况是,您可以在 web.config 中添加 404 错误的默认处理程序,这样,如果 HttpModule 无法捕获该事件,您仍然有机会“做某事” 。根据您尝试在 EndRequest 事件中完成的任务,您仍然可以使用解决方法。

<customErrors defaultRedirect="ErrorPage.aspx" mode="On">   
    <error statusCode="404" redirect="filenotfound.aspx" />
</customErrors>

First thing I'd try, is to tell IIS not to verify the file exists, which would allow the request to pass through to the HttpModule. You can do this for any particular file mapping, including the wildcard.

If the above isn't an option, worse case scenario you could add a default handler for the 404 error in the web.config, so that if the HttpModule can't catch the event, you still have a chance to 'do something'. Depending on what you are trying to accomplish in the EndRequest event, you may still be able to use the workaround.

<customErrors defaultRedirect="ErrorPage.aspx" mode="On">   
    <error statusCode="404" redirect="filenotfound.aspx" />
</customErrors>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文