Hello Imar,
In your book at the page 669-670. When i request example an non-existant file such DefaultTest.aspx the error appear (The page Error 404 get displayed) and the error is logged (Cause ive wrote it so it log it in a text file intead of by mail).
However, ive opened ErrorHandling.aspx (in the Demos folder) i wanted to test the other error.. so i removed the try.. catch and then the page "An unknown error occured" appear (The one defined in Error/OtherErrors.aspx).
All is okay but the problem is that others errors doesnt get logged in the text file.. wonder what happening ? it work for the 404 status code but not the 500.
I did as the exercise said :
config.web:
Code:
</connectionStrings>
<system.web>
<customErrors mode="On" defaultRedirect="~/Errors/OtherErrors.aspx" redirectMode="ResponseRewrite">
<error statusCode="404" redirect="~/Errors/Error404.aspx" />
</customErrors>
<profile>
Global.asax :
Code:
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when an unhandled error occurs
If HttpContext.Current.Server.GetLastError() IsNot Nothing Then
Dim myException As Exception = HttpContext.Current.Server.GetLastError().GetBaseException()
'Open a file for writing
Dim FILENAME As String = Server.MapPath("Logs\Errors.txt")
'Get a StreamWriter class that can be used to write to the file
Dim objStreamWriter As StreamWriter
objStreamWriter = File.AppendText(FILENAME)
'Append the the end of the string, "A user viewed this demo at: "
'followed by the current date and time
objStreamWriter.WriteLine(DateTime.Now().ToString("d") & " : " & myException.Message & " - " & Request.QueryString.ToString())
'Close the stream
objStreamWriter.Close()
End If
End Sub
Can you help me ?
Thanks.