Server.GetLastError

H

hansiman

In my web.config I have:

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

in error.aspx I try to get the last error and do something with it:

Dim ex As Exception = Server.GetLastError

I get Nothing (ex = Nothing)

Is the reason for ex = Nothing that Server.GetLastError only gets
exceptions manually thrown?

If not how do I then access the last error?

/M
 
C

Craig Deelsnyder

In my web.config I have:

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

in error.aspx I try to get the last error and do something with it:

Dim ex As Exception = Server.GetLastError

I get Nothing (ex = Nothing)

Is the reason for ex = Nothing that Server.GetLastError only gets
exceptions manually thrown?

If not how do I then access the last error?

/M

In essence the unhandled exception bubbles to the Page_Error level, and
then if not caught or cleared there, it continues to the Application_Error
(in global.asax). If you do not call Context.ClearError() at any point,
the built-in error handling then redirects to your error page you have
defined in your web.config. But after the redirect you've lost access to
the error.

A rather lengthy article with alternatives is here:

http://www.dotnetjohn.com/articles.aspx?articleid=42

basically if you want to display the error, you can call
Context.ClearError() after getting a reference to it, and either
Reponse.Write or redirect to some page of your own.
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top