Wrox Programmer Forums
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old May 20th, 2010, 02:43 PM
Friend of Wrox
Join Date: Mar 2010
Posts: 99
Thanks: 21
Thanked 6 Times in 4 Posts
Default 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 :

    <customErrors mode="On" defaultRedirect="~/Errors/OtherErrors.aspx" redirectMode="ResponseRewrite">
      <error statusCode="404" redirect="~/Errors/Error404.aspx" />
Global.asax :
 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
        End If
    End Sub
Can you help me ?

Old May 20th, 2010, 03:04 PM
Friend of Wrox
Join Date: Mar 2010
Posts: 99
Thanks: 21
Thanked 6 Times in 4 Posts

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
HTTP Status 404 - /TomcatProject/JSPDemo.jsp = ERROR gk03 Servlets 1 October 5th, 2009 01:15 AM
HTTP Status 404 rivcam JSP Basics 7 June 3rd, 2008 09:32 PM
Status 404 for 404 page marun BOOK: Professional Apache Tomcat 0 August 30th, 2005 06:45 AM
Http Status 500 ashutosh9910 Apache Tomcat 0 December 22nd, 2004 03:04 AM
HTTP status 404 brianjs JSP Basics 2 October 26th, 2003 03:06 PM

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