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
--
Site:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
Short urls & more:
http://ittyurl.net
"Paul Cheetham" wrote:
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