HttpModule 似乎仅针对静态页面触发

发布于 2024-10-14 15:02:46 字数 1629 浏览 2 评论 0原文

我有一个 HttpModule 用于处理在 Visual Studio 开发环境中启动和运行的错误。效果很好。对于客户端来说,存在硬404并且没有明显的重定向。谷歌分析应该对此感到非常满意。

Visual Studio 2008 中进行调试,当导航到本地主机时:

[port]/this_page_doesnt_exist.html, I get a our 404 error page and the hard 404.  

它也适用于开发服务器,

localhost:[port]/this_page_doesnt_exist.aspx.

当我将其全部移植到我们的 IIS7 Web 服务器时,我得到了它的工作方式与静态 HTML 文件完全一样。但是,我确定我的模块根本没有被 aspx 文件调用。如果我关闭 customErrors Off,我会得到标准的丑陋 404 页面。 (如果 customErrorsRemoteOnly,这些确实会起作用。)

线索似乎指向一些我没有正确设置的 IIS 设置调整过,但我一生都找不到它。有什么想法吗?

更多信息:

我正在集成模式下运行,我的web.config包含以下部分:

<configuration>
    <system.web>
      <httpModules>
        <add name="ErrorModule" type="HttpModules.ErrorModule, HttpModules"/>
      </httpModules>
    </system.web>
    <system.webServer>
      <validation validateIntegratedModeConfiguration="false"/>
      <modules>
        <add name="ErrorModule"  preCondition="managedHandler" type="HttpModules.ErrorModule, HttpModules"/>
      </modules>
    </system.webServer>
</configuration>

更多信息

我认为发生了什么IIS7 并不是发生的事情。我在服务器上看到 HTML 文件的 404 错误消息的唯一原因是 CustomErrorHandler 本机模块正在获取它。当我关闭该模块时,我现在可以为 aspx 文件运行 ErrorHandler,但不能为 HTML 文件运行。

我一定很接近了,但我一直在努力完成剩下的设置。有人能把我推过球门线吗?

I have an HttpModule for handling errors up and running in the visual studio development environment. It works well. To the client, there are hard 404s and no apparent redirects. Google Analytics should be very happy with this.

Debugging in Visual Studio 2008, when one navigates to localhost:

[port]/this_page_doesnt_exist.html, I get a our 404 error page and the hard 404.  

It also works on the development server for

localhost:[port]/this_page_doesnt_exist.aspx.

When I port it all over to our IIS7 web server, I've got it working exactly as it should for the static HTML files. However, I've determined that my module isn't getting called at all for aspx files. If I turn customErrors Off, I get the standard ugly 404 page. (If customErrors is RemoteOnly, these do kick in.)

The clues seem to be pointing at some IIS setting that I don't have properly tweaked, but I can't for the life of me find it. Any ideas?

More information:

I'm running in integrated mode and my web.config contains the following sections:

<configuration>
    <system.web>
      <httpModules>
        <add name="ErrorModule" type="HttpModules.ErrorModule, HttpModules"/>
      </httpModules>
    </system.web>
    <system.webServer>
      <validation validateIntegratedModeConfiguration="false"/>
      <modules>
        <add name="ErrorModule"  preCondition="managedHandler" type="HttpModules.ErrorModule, HttpModules"/>
      </modules>
    </system.webServer>
</configuration>

Yet More Information

What I thought was happening in IIS7 was not what was happening. The only reason I saw the 404 error message for HTML files on the server was that the CustomErrorHandler native module was getting it. When I turned that module off, I now get my ErrorHandler to run for aspx files, but not for HTML files.

I must be close, but I've struggled to get my settings the rest of the way. Can anyone push me over the goal line?

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

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

发布评论

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

评论(2

姜生凉生 2024-10-21 15:02:46

我敢打赌,在使用集成管道时,您没有在 IIS 7 的 web.config 中正确注册该模块。要让 HTTP 模块与 IIS 7 配合良好,您还需要在 部分中注册该模块,如下所示:

<configuration>
    <system.web>
        <httpModules>
            <add name="..." type="..." />
        </httpModules>
    </system.web>

    <system.webServer>
            <validation validateIntegratedModeConfiguration="false" />

            <modules>
                <add name="..." type="..." preCondition="managedHandler" />
            </modules>
    </system.webServer>
</configuration>

我认为您拥有 < /code> 部分而不是 部分?

另一方面,您使用什么错误日志记录模块?如果您使用自己自制的,我可以建议您使用 ELMAH 吗?它很容易上手,是开源的,并且被广泛使用,因此您可以放心,错误和问题都已得到解决。

快乐编程!

I'd wager you do not have the module properly registered in web.config for IIS 7 when using the integrated pipeline. To have the HTTP Module play nice with IIS 7 you need to also register the module in the <system.webServer> section like so:

<configuration>
    <system.web>
        <httpModules>
            <add name="..." type="..." />
        </httpModules>
    </system.web>

    <system.webServer>
            <validation validateIntegratedModeConfiguration="false" />

            <modules>
                <add name="..." type="..." preCondition="managedHandler" />
            </modules>
    </system.webServer>
</configuration>

I take it you have the <httpModules> section but not the <system.webServer> section?

On an aside, what error logging module are you using? If you are using your own home-baked one, might I suggest using ELMAH? It's easy to get started with, is open-source, and is widely used, so you can rest assured that the bugs and kinks are ironed out of it.

Happy Programming!

救赎№ 2024-10-21 15:02:46

经过相当多的斗争,我的结论是答案是:
“特定 Web 服务器上现有模块的交互,以及 web.config 和 IIS 设置如何支持错误处理,可能会导致开发人员特有的罕见复杂情况。值得庆幸的是,如果您想添加 HttpModule 来进行错误处理,这个变幻莫测的问题可以通过开源工具解决,例如 ELMAH”。 (我不能保证 ELMAH,但我查看了代码,似乎需要做比我所做的更多的事情才能让它工作。)

但是如果你已经走到这一步,你应该知道我要做什么:

在 IIS 管理器中,我修改了模块顺序,以便我的错误处理程序位于本机 CustomErrorModule 之前。 (或者,按照您想要的顺序在站点根 web.config 中重新指定所有模块。)仅在托管代码上运行您的模块。

由于某种原因,我的模块没有注意到丢失静态页面的请求,即使它正在运行静态页面。考虑一下我未解决的问题(大概 ELMAH 确实解决了)。

在 IIS 管理器中,我将错误页面设置为指向自定义错误页面。这是针对静态页面的。它们是设置 Response.StatusCode 的 aspx 文件。瞧!所有内容的硬错误代码。

After quite a bit of struggle, my conclusion is that the answer is:
"The interaction of existing modules on your particular web server, and how error handling is supported by your web.config and IIS settings, can lead to uncommon developer-specific complications. Thankfully, if you want to add an HttpModule for error handling, the vagaries of the problem are solved by open source tools, such as ELMAH". (I can't vouch for ELMAH, but I looked in the code, and it seems to need to do a lot more than what I was doing to get it to work.)

But if you've come this far, you deserve to know what I got to work:

In IIS Manager, I modified the Module order such that my error handler came before the native CustomErrorModule. (Or, respecify all your modules in the site root web.config in the order you want them.) Run your module only on managed code.

For some reason, my module doesn't notice requests for missing static pages, even though it is running for static pages. Consider that my unsolved problem (that, presumably, ELMAH does solve).

In IIS Manager, I set Error Pages to point to custom error pages. This is for the static pages. They were aspx files that set the Response.StatusCode. Voila! Hard error codes for everything.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文