jimseiwert
asked on
ASP.NET Error Handler
I have a .net web application and in my config file i have
<customErrors mode="On" defaultRedirect="~/error.a spx" />
Then on the error page I use Server.GetLastError.ToStri ng which is not working it returns "Object reference not set to an instance of an object."
How do i get the error the redirected the user to the default error page so i can correct it.
Thank you
<customErrors mode="On" defaultRedirect="~/error.a
Then on the error page I use Server.GetLastError.ToStri
How do i get the error the redirected the user to the default error page so i can correct it.
Thank you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
this is what i got
error.bmp
error.bmp
please dont put this on page load event . it is not correct ... check this post for details
https://www.experts-exchange.com/questions/21134839/Server-GetLastError-is-Nothing-on-custom-error-page.html
https://www.experts-exchange.com/questions/21134839/Server-GetLastError-is-Nothing-on-custom-error-page.html
ASKER
Ops, i just posted my comment on the wrong thread. I added the below code and placed a break point on the sub you told be to add but it never gets called on my generic error page that the web.config redirects it to. What am i missing?
Thank you for your patience
Thank you for your patience
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.Mail
Imports System.Diagnostics
Partial Class Sessions
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Sub Page_Error(ByVal sender As Object, ByVal e As EventArgs)
Dim PageException As String = Server.GetLastError().ToString()
Dim strBuild As New StringBuilder()
strBuild.Append("Exception!")
strBuild.Append(PageException)
Response.Write(strBuild.ToString())
Context.ClearError()
End Sub
see that event called when some error comes in your page ,, nor that page is loaded .. try to throw some error on page laod and see
ASKER
but this is the generic page that the web.config file calls when the application has an error. If i force an error then the server,getlasterror will retun the wrong error wont it ?
see this Page_Error error call when that page has error , for application related error you need to write code in global.asax in application_error event
HttpContext.Current