I have a custom error page on IIS8.5. Sometimes the error page itself throws an exception:
Object reference not set to an instance of an object.
This is part of my code behind:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
HttpContext.Current.Response.StatusCode = 500
'Dim CurrentException As Exception = Server.GetLastError()
'virheettxt.text = CurrentException.Message
Dim hostName = System.Net.Dns.GetHostName()
Dim ctxOBJ As HttpContext
Dim exceptionOBJ As Exception
Dim errorInfoTXT As String
ctxOBJ = HttpContext.Current()
exceptionOBJ = ctxOBJ.Server.GetLastError()
errorInfoTXT = " <br>Offending URL: " & iif(Not ctxOBJ Is Nothing, ctxOBJ.Request.Url.ToString(), "ei saatavilla") &
"<br>Source: " & iif(Not exceptionOBJ Is Nothing, exceptionOBJ.Source.ToString(), "ei saatavilla") &
"<br>Message: " & iif(Not exceptionOBJ Is Nothing, exceptionOBJ.Message.ToString(), "ei saatavilla") &
"<br>Stack trace: " & iif(Not exceptionOBJ Is Nothing, exceptionOBJ.StackTrace.ToString(), "ei saatavilla") &
"<br>Target Site: " & iif(Not exceptionOBJ Is Nothing, exceptionOBJ.TargetSite.ToString(), "ei saatavilla") &
"<br>Server: " & hostName
Dim virheurlsc = ctxOBJ.Request.Url.ToString()
ctxOBJ.Server.ClearError()
Error comes from line: errorInfoTXT = "
Offending URL: ......
And if there is a way to capture the error line I would really need it too on some cases...?