ASP.NET / Web.config:customErrors仅在404上重定向

时间:2021-03-23 12:24:12

I have this scenario:

我有这种情况:

A user comes to my site and followes a link, wich doesnt exists anymore, he should be redirected to a custom errorpage. (that works)

用户来到我的网站并关注链接,不再存在,他应该被重定向到自定义errorpage。 (这样可行)

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

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

This is my current Web.config:

这是我目前的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>

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

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

Server Error in '/' Application

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

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.

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

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".

详细信息:要在远程计算机上查看此特定错误消息的详细信息,请在位于当前Web应用程序根目录中的“web [.config”配置文件中创建标记。然后,此标记应将其“mode”属性设置为“Off”。

[...]

But in this case i want to show the stacktrace.

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

How can i do this?

我怎样才能做到这一点?

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

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

2 个解决方案

#1


15  

In the following web.config entries, a not found (404) condition will send a user to PageNotFound.aspx

在以下web.config条目中,未找到(404)条件会将用户发送到PageNotFound.aspx

Use mode="Off" and everyone (local and remote users) will see error details.

使用mode =“Off”,每个人(本地和远程用户)都会看到错误详细信息。

<customErrors mode="Off">
     <error statusCode="404" redirect="~/errorPages/PageNotFound.aspx" />
</customErrors>

Use mode="RemoteOnly" and local users will see detailed error pages with a stack trace and compilation details. Remote users with be presented with the GeneralError.aspx page

使用mode =“RemoteOnly”,本地用户将看到包含堆栈跟踪和编译详细信息的详细错误页面。向远程用户显示GeneralError.aspx页面

<customErrors mode="RemoteOnly" defaultRedirect="~/errorPages/GeneralError.aspx">
     <error statusCode="404" redirect="~/errorPages/PageNotFound.aspx" />
</customErrors>

#2


0  

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

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

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.

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

#1


15  

In the following web.config entries, a not found (404) condition will send a user to PageNotFound.aspx

在以下web.config条目中,未找到(404)条件会将用户发送到PageNotFound.aspx

Use mode="Off" and everyone (local and remote users) will see error details.

使用mode =“Off”,每个人(本地和远程用户)都会看到错误详细信息。

<customErrors mode="Off">
     <error statusCode="404" redirect="~/errorPages/PageNotFound.aspx" />
</customErrors>

Use mode="RemoteOnly" and local users will see detailed error pages with a stack trace and compilation details. Remote users with be presented with the GeneralError.aspx page

使用mode =“RemoteOnly”,本地用户将看到包含堆栈跟踪和编译详细信息的详细错误页面。向远程用户显示GeneralError.aspx页面

<customErrors mode="RemoteOnly" defaultRedirect="~/errorPages/GeneralError.aspx">
     <error statusCode="404" redirect="~/errorPages/PageNotFound.aspx" />
</customErrors>

#2


0  

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

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

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.

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