Custom Errors

Discussion in 'ASP.NET / ASP.NET Core' started by seppey, Jul 4, 2003.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Does anyone know if there is anyway to get custom error pages to work?

    I have tried creating a .htaccess file which points to my custom 404 error page (admin/error.aspx) but if I point to a file that is not there, then the normal windows 404 error appears.

    Can custom errors be aspx files?

    [?]

    Humanitad.org
     
  2. yes, custom error pages are easy to set up in .NET and you can use .ASPX pages. All you need to do is edit your web.config file a little bit. The setup is very flexible, you can have a page to catch specific errors, such as 404 errors, as well as a default error page.

    In your web.config file look for the <customErrors/> tag. By default I believe it is set to "RemoteOnly," meaning that detailed .NET error messages will be shown in the page only if you are actually on the server machine (not too useful in a hosted scenario.) If your 404 page is "My404.aspx," in your web root then your would change this to read:
     
  3. I only seem to be able to get the custom error sot work with aspx page request. For example if you click on the following url should get a custom error.

    www.sanjuanflows.info/oops.aspx

    However, I dont get a custom error with

    www.sanjuanflows.info/oops

    I don't understand why. Here is the section of my webconfig.

    <customErrors defaultRedirect="Error.aspx" mode="RemoteOnly" >
    <error statusCode="404" redirect="Error.aspx?errCode=404" />
    <error statusCode="500" redirect="Error.aspx?errCode=500" />
    </customErrors>

    I have an error page that accepts parameters so I can generate different messages on the same page.

    Any ideas?

    Thanks

    Brian




    quote:Originally posted by pjoyce

    yes, custom error pages are easy to set up in .NET and you can use .ASPX pages. All you need to do is edit your web.config file a little bit. The setup is very flexible, you can have a page to catch specific errors, such as 404 errors, as well as a default error page.

    In your web.config file look for the <customErrors/> tag. By default I believe it is set to "RemoteOnly," meaning that detailed .NET error messages will be shown in the page only if you are actually on the server machine (not too useful in a hosted scenario.) If your 404 page is "My404.aspx," in your web root then your would change this to read:
     
  4. Takeshi Eto

    Takeshi Eto DiscountASP.NET Staff

    Yes, this method will only work for .aspx pages. We are working on a tool where you can specify the customer error pages for other extensions.

    DiscountASP.NET
     
  5. Thanks for clearning this up - I thought I was doing something wrong.

    Brian
    quote:Originally posted by dasp

    Yes, this method will only work for .aspx pages. We are working on a tool where you can specify the customer error pages for other extensions.

    DiscountASP.NET
    </blockquote id="quote"></font id="quote">
     
  6. pjoyce, I would appreciate if you could post the code you mentioned you have in your global file to email you any errors.

    Thanks!
     
  7. Sure, I'll be glad too, but I'm a bit busy day and night until friday. Can you wait until this weekend?

    quote:Originally posted by arby

    pjoyce, I would appreciate if you could post the code you mentioned you have in your global file to email you any errors.

    Thanks!
    </blockquote id="quote"></font id="quote">
     
  8. Sure, no problem. Thanks!

    quote:Originally posted by pjoyce

    Sure, I'll be glad too, but I'm a bit busy day and night until friday. Can you wait until this weekend?

    quote:Originally posted by arby

    pjoyce, I would appreciate if you could post the code you mentioned you have in your global file to email you any errors.

    Thanks!
    </blockquote id="quote"></font id="quote">
    </blockquote id="quote"></font id="quote">
     
  9. This is in C# but I'm guessing people can translate to VB.NET. If you make any improvements to the code, I'd appreciate it if you could let me know. There are a couple of things that are specific to my application, namely the e-mail address and configuration parameters. I have a configuration parameter to turn the e-mail of errors on or off and another for the e-mail address to send to. Both these are in the web.config file. Your global.asax should already have a method for Application_Error which gets called for all .ASPX errors. You will have to add the ParseException method.

     
  10. Thanks, this worked great!
     
  11. Takeshi Eto

    Takeshi Eto DiscountASP.NET Staff

    We launched an IIS Manager tool in the control panel where you can control your 404 and 500 error pages.

    DiscountASP.NET
     
  12. Thanks for your code pjoyce

    Is there a way to e-mail handled errors as well?
    I tested your code and application_error in global.asax does not fire if there is an handled error - but still I want to know about these errors as well.

    Malin
     
  13. quote:Originally posted by Malin

    Thanks for your code pjoyce

    Is there a way to e-mail handled errors as well?
    I tested your code and application_error in global.asax does not fire if there is an handled error - but still I want to know about these errors as well.

    Malin
    </blockquote id="quote"></font id="quote">

    The application doesn't know if you handle an error, so there is no "universal" way of doing it. You would have to put the code to e-mail you the error in the catch statement.
     
  14. quote:Originally posted by pjoyce

    quote:Originally posted by Malin

    Thanks for your code pjoyce

    Is there a way to e-mail handled errors as well?
    I tested your code and application_error in global.asax does not fire if there is an handled error - but still I want to know about these errors as well.

    Malin
    </blockquote id="quote"></font id="quote">

    The application doesn't know if you handle an error, so there is no "universal" way of doing it. You would have to put the code to e-mail you the error in the catch statement.
    </blockquote id="quote"></font id="quote">

    OK, then I will create a class for this where the constructor does the mailing and then make an instance of this class in every catch. This leaves med with just one line of code in every catch.. which I find acceptable.

    Thanks for your answer

    Malin
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page