Asp – Missing aspx page is causing a global exception instead of redirecting to 404 page

asp.net

I have a global exception handler in global.asax.cs file in the Application_Error handler which redirects to the error.aspx page.
I also have the customError section in my web.config file. When I request a non existing aspx page, the 404.aspx file is NOT shown and the Application_Error handler is fired.

I was expecting 404.aspx to be shown.

<customErrors mode="RemoteOnly" defaultRedirect="error.aspx">
            <error statusCode="404" redirect="404.aspx"/>
        </customErrors>

Best Answer

Are you viewing the website locally? Because if locally then you'll see an error page since you have the mode set to RemoteOnly. Set mode="On" and see if you get the 404.aspx page.

Related Topic