Redirected to Default.aspx instead of set error 500 page on exception

525 Views Asked by At

In the site settings of our DotNetNuke installation, we set the Default Page for "500 Error Page" as you can see below. Site Settings Default Pages DotNetNuke

After setting this, we were expecting to be redirected when an error occurs. Instead we're still redirected the the "Default.aspx?tabid=..." page.

Why isn't the correct page shown?
What do we need to change for it to work?

(We're using v9.02.00 366, .NET Framework 4.6)


EDIT: Here's how I force the error to occur using a custom module.

public partial class TriggerError500 : PortalModuleBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(UserId == -1)
        {
            throw new NotImplementedException();
        }
    }
}

This module has been placed on a public page to test the error 500 page.

4

There are 4 best solutions below

2
On

Due to the way that DNN handles the loading of modules, and pages, the code that you are writing does not actually trigger an HTTP 500 error, as the page itself is loaded properly. The module loading error is captured by the framework and the error is logged to the Admin Logs, but the page itself is rendered.

You typically get an HTTP 500 error when you cannot connect to the database or otherwise, in those cases the DNN will adhere to the rules.

It is possible, that you could set Response.StatusCode = 500; and then end the response and get the desired behavior, but i have NOT tested this.

1
On

A setting that will affect error handling at a platform level can be toggled in the security section

Screen Shot here

2
On

The 500 error page will most likely only be used when an exception is completely unhandled. For example, if an exception is handled by a developer, then a friendly message will be shown on the page with part of the exception in the URL. This may account for the URL thing you're seeing. It's the same page as the module in question, but in a different format.

When the exception is not handled, a visitor would ordinarily be shown the infamous "yellow screen of death" (YSOD) with error details. Depending on the settings in the web.config, the level of detail will be generic or detailed. I believe that this is the use case intended for the 500 error page. This is when you should see it.

2
On

If my memory serves me right, you may want to try this in your web.config:

<customErrors mode="On" defaultRedirect="500" />