3

For some reason, when I get an ASP.NET runtime error, it's not loading my custom error page

<customErrors mode="On" defaultRedirect="app_offline.htm" redirectMode="ResponseRewrite">
    <error statusCode="404" redirect="app_offline.htm"/>
        <error statusCode="500" redirect="app_offline.htm"/>
</customErrors>

That's in my web.config.

I'm still getting this though and it's not loading my error .htm page:

Server Error in '/' Application.
Runtime Error
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 <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".

<!-- Web.Config Configuration File -->

<configuration>
    <system.web>
        <customErrors mode="Off"/>
    </system.web>
</configuration>


Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.

<!-- Web.Config Configuration File -->

<configuration>
    <system.web>
        <customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
    </system.web>
</configuration>
PositiveGuy
  • 43,266
  • 106
  • 285
  • 457
  • I'll update the thread...I get the typical error about custom errors. This is being hosted on discountasp.net – PositiveGuy Oct 20 '10 at 06:53
  • Why to you use the app_offline.htm as custom error ? this file first of all if exist is stopping you web app. Second open the errors to see the real error. (or see your log) – Aristos Oct 20 '10 at 07:02
  • 1
    So here's the deal. I don't want to fix the error. I want to redirect to my custom error page and call it a day and go to bed. This should be redirecting me! – PositiveGuy Oct 20 '10 at 07:04
  • Is it a special reason you have `redirectMode="ResponseRewrite"`? When you have problems, you should first try the default (which is `redirectMode="ResponseRedirect"`, or remove the setting entirely). Then you will maybe see what it actually tried to redirect to.. – awe Oct 20 '10 at 07:06
  • I have already tried taking that out before I posted this thread; doesn't matter with the redirectMode – PositiveGuy Oct 20 '10 at 07:06
  • @CoffeAddict if you do not won to fix the error, then is probably have an error on the compile (and its not a throw error). Maybe its not find some dll, or you have an error on web.config. If there is some of this error then the program can not redirect but show this error. If can not read the web.config, then its not be able to run this part of code - so if there is an error on config... – Aristos Oct 20 '10 at 07:16
  • @Aristos: The reason for using this is to hide details from the end user. If he wants to do this, it's up to him. I guess he wants to set `mode="On"` first to test if it works (which it obviously don't) before he sets `mode="RemoteOnly"`... Anyway, the reasons for doing it is really not our concern, its only up to us to try to give answers that will help him solve this problem about not showing the custom error page. He is not asking us to solve the error thrown in the first place! – awe Oct 20 '10 at 07:57

5 Answers5

7

I'm pretty sure that app_offline.htm is a reserved filename in ASP.NET that will always be served if present on the server.

Try renaming it to error.htm and updating your <customErrors /> block to match.

James Simm
  • 1,540
  • 1
  • 18
  • 27
  • That's not it. I have the exact same problem and my page is called DisplayMyVeryOwnSpecialError.htm – Vladimir Kocjancic Aug 23 '12 at 07:25
  • If you read the original question, you can see he has app_offline.htm configured as the `defaultRedirect`, as well as the `redirect` for 404 and 500. app_offline.htm will always be served as I said, so the answer is valid. I suspect you have an unrelated issue. – James Simm Aug 23 '12 at 11:06
  • I think you misread some info, because what app_offline.htm did was that it unloaded your app, if the file was in app root directory. Obviously he doesn't have a problem with unloaded app, but rather with error page not displaying. On top of that I don't think that app_offline.htm feature was in .NET 3.5 as CoffeeAddict says. – Vladimir Kocjancic Aug 28 '12 at 19:52
  • The app_offline.htm feature has been in ASP.NET since .Net 2.0. Either way, this is adding nothing to the original question... his issue was that we was running a .Net 4.0 application in a .Net 2.0 application pool. – James Simm Sep 03 '12 at 08:13
1

I suspect what's happening is that ASP.NET can't find your custom error page. The path to your error page file needs to be relative or absolute. So either:

<customErrors mode="On" defaultRedirect="~/app_offline.htm" redirectMode="ResponseRewrite">
    <error statusCode="404" redirect="~/app_offline.htm"/>
    <error statusCode="500" redirect="~/app_offline.htm"/>
</customErrors>

Or:

<customErrors mode="On" defaultRedirect="http://mysite.com/app_offline.htm" redirectMode="ResponseRewrite">
    <error statusCode="404" redirect="http://mysite.com/app_offline.htm"/>
    <error statusCode="500" redirect="http://mysite.com/app_offline.htm"/>
</customErrors>

Should solve your problem.

Mark Bell
  • 27,184
  • 22
  • 109
  • 138
  • you don't always need to use ~. Sure you can but you can also use redirect="app_offline.htm" as it's already in the root of my application and I'm hitting root when I go to my site already...no need for the extra ~ – PositiveGuy Oct 20 '10 at 14:01
  • “I'm hitting root when I go to my site already...no need for the extra ~” Yes, but if you go to a URL that *isn't* relative to the root and an error occurs, then the relative path to `app_offline.htm` will no longer be correct. Anyway, glad you figured it out. – Mark Bell Oct 20 '10 at 14:41
0

Do you get details of the actual error if you set mode="Off"? If you still get the same default error page, you might find the solution in this post:

CustomErrors mode="Off"

Community
  • 1
  • 1
awe
  • 20,650
  • 5
  • 76
  • 84
0

Problem was my site was running under .NET 3.5 when it's a 4.0 app

PositiveGuy
  • 43,266
  • 106
  • 285
  • 457
0

I also had the same issue. Main problem is related to visibility of your error pages to various users. It is controlled by the tag

Mode

as shown below enter image description here

I think you have used RemoteOnly . In order to show the custom error page while running in your local machine we have to make the mode value as On. For me it is worked afterwords.

Also we can give error pages for various types of error codes. For example in below figure you can see - I have given redirecting page as CustomErrorAspxPage.aspx for file not found exception type for the status code 404. enter image description here

At last in order to test this I created exceptions 1)for default exception 2)for 404 file not exists exception as shown in below figure. enter image description here

Rinoy Ashokan
  • 1,167
  • 14
  • 13