带有的自定义 404 页面该元素似乎在 IIS 7 中不起作用

发布于 2024-10-14 03:05:06 字数 1633 浏览 5 评论 0原文

我正在使用托管管道模式=“集成”测试 IIS 7.5 站点。

我的站点面向移动设备,并利用格式良好的 URL 以最少的输入传递参数。例如,“mysite.com/bob1234”在本例中“bob1234”实际上是参数。

在 Application.BeginRequest 中,我使用正则表达式处理 Request.Url.AbsolutePath 以确定 URL 的格式是否正确。

如果用户输错 URL(即 mysite.com/boob1234),我想添加自定义 404 页面。

<system.web>
    <customErrors mode="RemoteOnly" defaultRedirect="~/MobileError.aspx">
      <error statusCode="404" redirect="404.htm"/>
    </customErrors>
</system.web>

虽然当扩展名是“.aspx”时它会捕获错误,但当没有映射处理程序时(例如“/mysite.com/boob1234”),它不会捕获 404(s)。

我按照说明操作,并向我的 system.webserver 添加了一个元素

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />        
    <httpErrors defaultResponseMode="Redirect" errorMode="DetailedLocalOnly">
      <remove statusCode="404" subStatusCode="-1"/>
      <error statusCode="404" prefixLanguageFilePath="" 
              path="/mobile/MobileError.aspx" responseMode="ExecuteURL"/>
    </httpErrors>        
</system.webServer>

,但似乎没有任何迭代起作用。当我取消注释该块时,出现 500 错误。不,我的代码似乎没有任何问题。即使我只是转发到纯 HTML 页面,我也会收到 500 错误。

我确实实现了失败的请求跟踪,以查看我能看到什么。

我得到了预期的: IIS Web Core 抛出的 404。

几步之后,CustomerErrorModule 启动,但失败并出现 500 错误。详细消息是

配置异常信息: \?\C:.....\MyApp\web.config ( 89) :该配置节不能 在此路径中使用。发生这种情况时 该部分被锁定在父级 等级。默认情况下锁定 (overrideModeDefault="Deny"),或设置 明确地通过位置标签 overrideMode="Deny" 或旧版 允许Override =“假”。

我尝试过遍历“.config”堆栈,但没有找到任何对 overrideMode="Deny" 的引用

。任何帮助都会很棒。现在完全卡住了。

谢谢: 迪伦

I'm testing an IIS 7.5 site with Managed Pipeline Mode = 'Integrated'

My site targets mobile devices and leverages well formed URLs to pass parameters with a minimum of typing. For example 'mysite.com/bob1234' in this case 'bob1234' is actually parameter.

In the Application.BeginRequest, I process the Request.Url.AbsolutePath using a regular expression to determine if the URL is well formed.

I wanted to add a Custom 404 page, if a user mistypes the URL i.e. mysite.com/boob1234.

<system.web>
    <customErrors mode="RemoteOnly" defaultRedirect="~/MobileError.aspx">
      <error statusCode="404" redirect="404.htm"/>
    </customErrors>
</system.web>

And while this catches errors when the extension is '.aspx', it does not catch 404(s) when no handler is mapped, for example '/mysite.com/boob1234'.

I followed the instructions and also added a element to my system.webserver

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />        
    <httpErrors defaultResponseMode="Redirect" errorMode="DetailedLocalOnly">
      <remove statusCode="404" subStatusCode="-1"/>
      <error statusCode="404" prefixLanguageFilePath="" 
              path="/mobile/MobileError.aspx" responseMode="ExecuteURL"/>
    </httpErrors>        
</system.webServer>

But no iteration of this seems to work. When I uncomment the block, I get a 500 error. And no, there doesn't seem to be any problem with my code. I get a 500 error, even when I just forward to an plain HTML Page.

I did implement failed request tracing to see what I could see.

I get the expected: 404 thrown by IIS Web Core.

Then a few steps later the CustomerErrorModule starts, but it fails with a 500 error. The detailed message is

ConfigExceptionInfo:
\?\C:.....\MyApp\web.config ( 89)
:This configuration section cannot be
used at this path. This happens when
the section is locked at a parent
level. Locking is either by default
(overrideModeDefault="Deny"), or set
explicitly by a location tag with
overrideMode="Deny" or the legacy
allowOverride="false".

I've tried walking up the '.config' stack, and haven't found any references to overrideMode="Deny"

Any help would be awesome. Totally stuck now.

Thanks:
Dylan

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

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

发布评论

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

评论(3

最偏执的依靠 2024-10-21 03:05:06

您是否尝试过解锁 applicationhost.config 中的配置部分?

<location path="example.net" overrideMode="Allow">
    <system.webServer>
        <httpErrors>
        </httpErrors>
    </system.webServer>
</location>

参考:http://learn.iis.net/page。 aspx/124/applicationhostconfig简介/#Locking

Have your tried unlocking the configuration section in the applicationhost.config?

<location path="example.net" overrideMode="Allow">
    <system.webServer>
        <httpErrors>
        </httpErrors>
    </system.webServer>
</location>

Reference: http://learn.iis.net/page.aspx/124/introduction-to-applicationhostconfig/#Locking

我不吻晚风 2024-10-21 03:05:06

只是摸索一下,尝试将此属性添加到 httpErrors 元素中:

existingResponse="PassThrough"

例如:

<httpErrors existingResponse="PassThrough" 
        defaultResponseMode="Redirect" 
        errorMode="DetailedLocalOnly">

Just a stab in the dark, try adding this attribute to the httpErrors element:

existingResponse="PassThrough"

For example:

<httpErrors existingResponse="PassThrough" 
        defaultResponseMode="Redirect" 
        errorMode="DetailedLocalOnly">
胡渣熟男 2024-10-21 03:05:06

这与 IIS 中请求的生命周期有关。在没有映射处理程序的情况下,404 在 ASP dll 被调用之前就会被识别。对于 IIS 中未明确标识为需要 Asp.Net 的项目,IIS 404 错误将触发并忽略 Asp.Net 中的任何指令。即使通配符应用于所有扩展,只有当 IIS 没有首先检测到 404 时才会调用该通配符。这包括 .Net 未明确处理的目录和所有文件扩展名。因此,如果您尝试访问 http://mydomain.com/images/someimage.gif 并且该文件不存在,您将不会收到 .Net 404 错误处理程序。如果将 .gif 更改为 .aspx,处理程序将随后触发。我见过的唯一能充分响应此问题的方法是更改​​ IIS 中的所有 404 处理程序,以重定向到本地站点上的 URL 文件。它将传递 aspxerror 查询字符串,但如果您在 url 声明中添加 ?error= ,您将能够添加特定信息。

我尝试过的另一件事(尽管我不确定是否正确)是在 IIS 中重新分配文件的映射。我们定义 Asp.Net 应在某一时刻处理所有对 .gif 的请求。我遇到的问题是图像没有出来,Base64 编码(我认为?)文本出来了。由于时间紧迫,我没有追求这个,因为更简单的解决方案是使用 IIS 自定义错误映射。

This has to do with the lifecycle of a request within IIS. In your case where there is no handler mapped, the 404 is recognized before the ASP dlls are even called into play. For items that are not explicitly identified in IIS as requiring Asp.Net, the IIS 404 error will fire and ignore any directives within Asp.Net. Even if a wild-card is applied to the all extensions, this wild-card is only called if IIS does not detect a 404 first. This includes directories and all file extensions not handled explicitly by .Net. So if you attempt to go to http://mydomain.com/images/someimage.gif and that file does not exist, you will not receive a .Net 404 error handler. If you change .gif to .aspx the handler will subsequently fire. The only method I have seen that adequately responds to this is to change all of your 404 handlers within IIS to redirect to a URL file on your local site. It will pass an aspxerror querystring, but if you put a ?error= in your url declaration, you will be able to add specific information.

One other thing I tried, though I'm not sure I tried it correctly, is reassigning the mapping for the file within IIS. We defined that Asp.Net should handle all requests for .gif at one point. The problem I had is that an image didn't come out, a Base64 encoding (I think?) text came out. Being under a deadline I did not pursue this as the simpler solution was to use the IIS custom errors mappings.

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