Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 559
Lyra Avatar asked Feb 15 '12 14:02

Lyra


1 Answers

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>
like image 161
Ray Van Halen Avatar answered Oct 23 '22 11:10

Ray Van Halen