Page_Error Working Only Part of the Time?

E

Erik Lautier

I've got Page_Error emailing me the message and stack trace when a
server error is generated, but it doesn't always work. My Page_Error
code:

Sub Page_Error(ByVal src As Object, ByVal args As EventArgs) Handles
MyBase.Error
Dim e As System.Exception = Server.GetLastError()
Session("Erro")= "Error: " & e.Message.ToString() & "<p>Stack Trace: "
& e.StackTrace.ToString()
Context.ClearError()
End Sub

My web.config file redirects the user to a "nice" error page, which
emails me the Session("Erro") so I can investigate the problem. What
I can't understand is that sometimes Session("Erro") is blank - I saw
two emails come through with errors on the same page today, with one
full of useful info, and one completely empty. What might explain
this?

Thanks,

Erik
 
M

Michael Nemtsev [MVP]

Hello Erik,

it means that u dont' have previous error.

Why you don't handle all errors on Application_Error method?

---
WBR,
Michael Nemtsev [Microsoft MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


EL> I've got Page_Error emailing me the message and stack trace when a
EL> server error is generated, but it doesn't always work. My Page_Error
EL> code:
EL>
EL> Sub Page_Error(ByVal src As Object, ByVal args As EventArgs) Handles
EL> MyBase.Error
EL> Dim e As System.Exception = Server.GetLastError()
EL> Session("Erro")= "Error: " & e.Message.ToString() & "<p>Stack Trace:
EL> "
EL> & e.StackTrace.ToString()
EL> Context.ClearError()
EL> End Sub
EL> My web.config file redirects the user to a "nice" error page, which
EL> emails me the Session("Erro") so I can investigate the problem.
EL> What I can't understand is that sometimes Session("Erro") is blank -
EL> I saw two emails come through with errors on the same page today,
EL> with one full of useful info, and one completely empty. What might
EL> explain this?
EL>
EL> Thanks,
EL>
EL> Erik
EL>
 
E

Erik Lautier

Thanks for your reply, Michael. It's not my server and I may not have
access to global.asax (I'm checking on this). Regardless, if
Page_Error is supposed to pull the last error and I'm storing it in a
Session variable, how could I not have the previous error?
 

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

Top