views:

207

answers:

2

I've been doing some research on how to globally handle errors in my ASP.NET application. I have settled on using the web.config file with the following code:

<customErrors mode="On" defaultRedirect="errorpage.aspx">
</customErrors>

Here is my errorpage.aspx.vb code:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim ex As Exception = Server.GetLastError
End Sub

The problem I am experiencing is Server.GetLastError ends up being nothing. What do I have to do to be able to access the last error info? Since it is on an asp form page, I shouldn't have to prepend HttpContext.Current. to the Server.GetLastError, correct?

Thanks

+3  A: 

You can capture global errors using the global.asax.

The error page is loaded via a simple http redirect and unfortunately doesn't know what the last error for a particular user was.

Chris Pebble
+1  A: 

Try using ELMAH to capture your errors. It's very customizable and will do the handling in the background without reporting it to your users. It can send the errors to and email and/or save them in a database. I use it on all my applications.

http://code.google.com/p/elmah/

craigmoliver