Problem with Server.GetLastError!

L

Lars Netzel

I'm trying to make my own custom error page... but when using
Try

lblErrormessage.Text = Server.GetLastError.Message

lblErrormessage.Text += "<br>" & Server.GetLastError.StackTrace

lblErrormessage.Text += "<br>" & Server.GetLastError.Source

Catch ex As Exception

lblErrormessage.Text = ex.Message

End Try

It goes into the Catch and says "Object reference not set to an instance of
an object." I have debugged alittle and Server is avaliable.. but
GetLastError gives the error..

Do I need to enable something in order to use this?

Regards/Lars Netzel
 
S

Shiva

Hi,
Check whether Server.GetLastError() returns any error object before
accessing its properties.

I'm trying to make my own custom error page... but when using
Try

lblErrormessage.Text = Server.GetLastError.Message

lblErrormessage.Text += "<br>" & Server.GetLastError.StackTrace

lblErrormessage.Text += "<br>" & Server.GetLastError.Source

Catch ex As Exception

lblErrormessage.Text = ex.Message

End Try

It goes into the Catch and says "Object reference not set to an instance of
an object." I have debugged alittle and Server is avaliable.. but
GetLastError gives the error..

Do I need to enable something in order to use this?

Regards/Lars Netzel
 
L

Lars Netzel

No I figured it out..

Since you are redirected to another errorpage you loose the GetLatsetError
information, cause you are not on that page anymore.. BUT.. if you in
Global.aspx in Page_error event (where it's still accessible) put
Server.GetLastError in a SESSION variable.. you can get it thru that on the
Errorpage ..

/Lars
 

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

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top