Trapping Http 500 error

  • Thread starter Thread starter Raymond Du
  • Start date Start date
R

Raymond Du

Hi,

I have an ASP.Net 1.1 web services project, occasionally it will encounters
500 or other errors, as you know 500 error could be a result of all kind of
problems. Instead of letting IIS display the error, can I trap the error
using ASP.Net and customize the error page or silently handle the error?

TIA
 
Yes, you can trap the errors. For that you would use:

catch (WebException wex)
{
HttpStatusCode httpStatus = HttpStatusCode.NotFound;

if (wex.Response is HttpWebResponse)
httpStatus = ((HttpWebResponse)wex.Response).StatusCode;
}

Hope it helps.
 
Thank you for your response.

Where should I put the code snippet in? In the page_load of every .aspx
files? I doubt the page_load get called when 500 error happens.

Thanks Again
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top