ASP.NET / Web.config: customErrors redirect only on a 404
Asked Answered
N

2

13

I have this scenario:

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)

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

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>

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

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

[...]

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.

Narbada answered 15/2, 2012 at 14:28 Comment(0)
N
0

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.

Narbada answered 16/6, 2014 at 18:16 Comment(0)
G
26

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

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

<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

<customErrors mode="RemoteOnly" defaultRedirect="~/errorPages/GeneralError.aspx">
     <error statusCode="404" redirect="~/errorPages/PageNotFound.aspx" />
</customErrors>
Garcia answered 19/4, 2012 at 13:41 Comment(0)
N
0

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.

Narbada answered 16/6, 2014 at 18:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.