p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning ASP.NET 4 : in C# and VB (http://p2p.wrox.com/forumdisplay.php?f=560)
-   -   Status error 404 work but not 500 ? (http://p2p.wrox.com/showthread.php?t=79486)

Rushino May 20th, 2010 02:43 PM

Status error 404 work but not 500 ?
 
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.

Rushino May 20th, 2010 03:04 PM

Bah sorry its my fault. i fixed it. The error was that this file Server.MapPath("Logs\Errors.txt" was not found if i use code from Demos folder its obvious. So i had to add ~ in front of Logs. Its rather funny.. cause i am in the debugger chapter so i tried the debugger to find the error lol


All times are GMT -4. The time now is 03:27 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.