Error details in Custom Error Page

P

Paul Cheetham

Hi,

I have created a custom error page for my web application (c#, .Net 2)
In this page I am trying to get the details of the error that has
occurred so that I can display it if required.

(Error page defined in Web.config)

I am using the following code:

HttpContext ctx = HttpContext.Current;
Exception ex = ctx.Server.GetLastError();

This always appears to return null for the exception.


How can I get the details of the exception that occurred that caused my
error page to be displayed?


Thankyou.


Paul
 
G

Guest

Paul,

I was posting another issue here and I noticed this thread. I tried the
same thing and had the same problem and I never found an answer. If you get
an answer on you own please post it here.

Thanks,
 
G

Guest

Normally you would have this code in Application_Error in global.asax.
Server.GetLastError().GetBaseException will return the true innerException
containing the error message.

Not sure if you need to but if you tried to do this on your custom error
page, and it was already retrieved in Application_Error, you might need to
store it in Session or Cache so that you can redisplay on your custom error
page. This will be especially true if you call Server.ClearError() after
getting the exception.

However, you might want to consider the security implications of displaying
exception information like this to the "public" on your site.
Peter

Peter
 
P

Paul Cheetham

I've not got any Page_Error or Application_Error handlers defined, and
so was expecting the full error details to be available to me.

I'm not worried about the security, as it's an Intranet site, and we
have a seting to turn detiled error reporting on and off for debugging
purposes.


Paul
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top