0

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

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.