ericnet
Programmer
- Mar 29, 2006
- 106
In order to get in which page an exception occurred, which is the best method I can use?
Request.QueryString.ToString()
Request.Url.AbsoluteUri
Request.Path
Request.Url.ToString()
... Others?
I need this information in Sub Application_Error() of Global.asax and in a Try/Catch block in the page, when logging the exception in Windows log file and reporting via mail:
(global.asax file)
(In the page)
Thank you
Request.QueryString.ToString()
Request.Url.AbsoluteUri
Request.Path
Request.Url.ToString()
... Others?
I need this information in Sub Application_Error() of Global.asax and in a Try/Catch block in the page, when logging the exception in Windows log file and reporting via mail:
(global.asax file)
Code:
<script language="VB" runat="server">
Sub Application_Error(Sender As Object, E As EventArgs)
Dim ex As Exception = Server.GetLastError().GetBaseException()
EventLog.WriteEntry("Test Web", "Message: " & ex.Message & _
"\nSOURCE: " & ex.Source & "\nTARGETSITE: " & ex.TargetSite & _
"\nSTACKTRACE: " & ex.StackTrace & [b]“\nPAGE/URL” & _ Request.Url.ToString()[/b], _ etc,..
‘Here send e-mail notification to administrator with same information logged above
...
message.Body = "<html><body><h1>[b]Page: " & Request.Url.ToString()[/b] & "</h1>" ............ "</body></html>"
SmtpMail.Send(MyMessage)
End Sub
</script>
(In the page)
Code:
Sub Page_Load(Sender As Object, E As EventArgs)
Try
‘Code here
Catch ex As Exception
EventLog.WriteEntry("Test Web", "Message: " & ex.Message & _
"\nSOURCE: " & ex.Source & "\nTARGETSITE: " & ex.TargetSite & _
"\nSTACKTRACE: " & ex.StackTrace & [b]“\nPAGE/URL” & _ Request.Url.ToString()[/b], _ etc,..
‘Here send e-mail notification to administrator with same information logged above
...
message.Body = "<html><body><h1>[b]Page: " & Request.Url.ToString()[/b] & "</h1>" ............ "</body></html>"
SmtpMail.Send(MyMessage)
End Try
End Sub
Thank you