ASP.NET/Web.config:customErrors 仅在 404 上重定向 [英] ASP.NET / Web.config: customErrors redirect only on a 404

查看:20
本文介绍了ASP.NET/Web.config:customErrors 仅在 404 上重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这种情况:

用户来到我的网站并点击了一个不再存在的链接,他应该被重定向到自定义错误页面.(有效)

A user comes to my site and follows a link, which doesn't exists anymore, he should be redirected to a custom errorpage. (that works)

如果用户做了某事引发了错误,他应该会看到 Stacktrace 和真正的 Errorpage.

If a user does something, that throws an error, he should see the Stacktrace and the real Errorpage.

这是我当前的 Web.config:

This is my current Web.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.web>
        <customErrors>
          <error statusCode="404" redirect="/errors/404.htm" />
        </customErrors>
        <compilation debug="true" strict="false" explicit="true" />
    </system.web>
</configuration>

使用此配置,404 将被重定向到正确的站点,但 HTTP 500 将显示如下:

with this configuration, a 404 will be redirected to the right site, but a HTTP 500 will be shown as following:

/"应用程序中的服务器错误

描述:服务器上出现应用程序错误.此应用程序的当前自定义错误设置可防止远程查看应用程序错误的详细信息(出于安全原因).但是,本地服务器计算机上运行的浏览器可以查看它.

Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.

详细信息:要在远程计算机上查看此特定错误消息的详细信息,请在web [.config"中创建一个标签.配置文件位于当前 Web 应用程序的根目录中.然后这个标签应该有它的模式".属性设置为关闭".

Details: To enable the details of this specific error message to be viewable on remote machines, please create a tag within a "web [.config" configuration file located in the root directory of the current web application. This tag should then have its "mode" attribute set to "Off".

[...]

但在这种情况下,我想显示堆栈跟踪.

But in this case I want to show the stacktrace.

我该怎么做?

注意:我们在 Linux 上使用 Mono <- FastCGI ->Lighttpd 构建.

Note: We're on Linux with a Mono <- FastCGI -> Lighttpd construction.

推荐答案

Ray Van Halens 答案是正确的,但这不是实际问题.

Ray Van Halens Answer is correct, but this was not the actual problem.

不显示堆栈跟踪的原因是单声道本身的错误.没有其他方法可以编写一个自己的错误页面来显示堆栈跟踪.

The reason for not showing stacktrace is a bug in mono itself. There is no other way then write an own error page where the stacktrace is dispayed.

这篇关于ASP.NET/Web.config:customErrors 仅在 404 上重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆