Extremebfn
04-19-2007, 12:21 AM
Hi Guys.. I want to use my own CustomError page to inform my users of errors on the page. Im am doing the following:
I have the following in my web.config:
<customErrors mode="On" defaultRedirect="mcerror.aspx" />
That enables customErrors on my web-application.
Now when a error occurs, it automaticly redirects the page to mcerror.aspx.
On in Page_Load event on mcerror.aspx i have the following code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim ex As Exception = Server.GetLastError
lblError.text = ex.Message.ToString
End Sub
Now acording to MSDN, the GetLastError method returns the last Exception. So i want to use the GetLastError method to show the error that was generated and then print that inside the Label(lblError), but it doesnt seem to work, i get the following error:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Might it be that GetLastError doesnt have a value? If so, how can i get the current error and display that, and not the previous error, because a current error might exsist, but a previous error might not?
Please any help would be appreciated.
Regards
I have the following in my web.config:
<customErrors mode="On" defaultRedirect="mcerror.aspx" />
That enables customErrors on my web-application.
Now when a error occurs, it automaticly redirects the page to mcerror.aspx.
On in Page_Load event on mcerror.aspx i have the following code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim ex As Exception = Server.GetLastError
lblError.text = ex.Message.ToString
End Sub
Now acording to MSDN, the GetLastError method returns the last Exception. So i want to use the GetLastError method to show the error that was generated and then print that inside the Label(lblError), but it doesnt seem to work, i get the following error:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Might it be that GetLastError doesnt have a value? If so, how can i get the current error and display that, and not the previous error, because a current error might exsist, but a previous error might not?
Please any help would be appreciated.
Regards