Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Error trapping not working


Message #1 by "Greg Quinn" <greg@i...> on Thu, 31 Jan 2002 12:57:38 -0800
I have created my global.asax file to write something to the windows event

log when an error occurs. In the page I tested the error, I made it look for

an xml file that does not exist. Instead of displaying the error in a

friendly format, or writing the error to the event log, I just get "Could

not find file" error as if I had no error handling at all?



Here is the code for the global.asax...



<%@ Import Namespace = "System.Diagnostics" %>

<script language = "vb" runat = "server">



Public Sub Application_OnEndRequest(Sender as Object, E as EventArgs)

	Response.Write("<hr size = 1>")

	Response.Write("<font face = arial size = 2>This page was served by

ASP.NET</font>")

End Sub



Public Sub Application_Error(Sender as Object, E as EventArgs)

	Dim logName as String = "Web_Errors"

	Dim Message as String

	Message = "Url: " & Request.Path

	Message += " Error: " & Server.GetLastError.ToString



	'Create Event Log if it doesn't exist

	IF (Not EventLog.SourceExists(LogName)) Then

		EventLog.CreateEventSource(logName, logName)

	End if



	'Fire off to event log

	Dim Log as new eventLog



	Log.Source = LogName

	Log.WriteEntry(Message, EventLogEntryType.Error)

End Sub



</script>




  Return to Index