Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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 :

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.
Reply With Quote
  #2 (permalink)  
Old May 20th, 2010, 03:04 PM
Friend of Wrox
 
Join Date: Mar 2010
Posts: 99
Thanks: 21
Thanked 6 Times in 4 Posts
Default

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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 12:14 AM.


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