2012-02-13 146 views
6

是否可以在全局級別捕獲Classic ASP中的所有500個錯誤?也許在IIS中的東西。目前我正在使用II6。我喜歡捕獲錯誤消息,然後將其存儲在數據庫中。我知道它可能在ASPX頁面中,但不知道你是如何在傳統的asp中做的。經典ASP:捕獲錯誤

謝謝

+0

IIS7有失敗的請求跟蹤,它報告未處理的經典ASP錯誤,不知道它是否存在於6.0中。 http://learn.iis.net/page.aspx/266/troubleshooting-failed-requests-using-tracing-in-iis/ – 2012-02-13 16:32:34

回答

13

是,創建一個ASP網頁,其中將記錄錯誤的詳細信息的數據庫,並設置這是在IIS中的500處理器如下頁面。

使用Server.GetLastError對象獲取處理程序腳本中錯誤的詳細信息。

在500處理程序中登錄到文本文件而不是數據庫可能是個好主意,以提高永續性。

Set Custom 500 Handler in IIS

+1

很好的答案... – Dan 2012-02-13 16:38:23

+0

這正是我一直在尋找的。謝謝喬恩。我現在就試試看。 – MindGame 2012-02-13 16:45:30

+0

當我response.write Server.GetLastError()我什麼都沒有得到。有任何想法嗎? – MindGame 2012-02-13 17:15:20

4

錯誤在傳統的ASP處理是一個完整的疼痛。您可以使用on error resume next捕獲您認爲會發生的錯誤,然後檢查以下代碼行中的錯誤代碼。

或者,您可以掃描服務器日誌中的500個錯誤。或在您的IIS設置中設置「500錯誤」頁面。

On Error Resume Next 
... do something... 
If Err.Number <> 0 Then 
... handle error 
end if 
5

補充Jon的回答,使用這個腳本錯誤寫入日誌文件:

<% 
'Set this page up in IIS to receive HTTP 500 errors 
''Type' needs to be 'URL' and the URL is e.g.: '/500Error.asp' if this file is named '500Error.asp' and is in the site root directory. 
'This script assumes there is a "/Log" folder, and that IIS has write access to it. 
Const ForReading = 1, ForWriting = 2, ForAppending = 8 
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0 

Dim objFSO, err 
Set objFSO=CreateObject("Scripting.FileSystemObject") 

Set err = Server.GetLastError() 

outFile=Server.MapPath("/Log/ErrorLog.txt") 
Set objFile = objFSO.OpenTextFile(outFile, ForAppending, True, TristateTrue) 

objFile.WriteLine Now & " - ERROR - ASPCode:" & err.ASPCode & " ASPDescription: " & err.ASPDescription & " Category: " & err.Category & " Description: " & err.Description & " File: " & err.File & " Line: " & err.Line & " Source: " & err.Source & vbCrLf 
objFile.Close 

Set objFile = Nothing 
Set err = Nothing 

%> 
0

要添加到@喬恩·伊斯特伍德的答案 - 如果你使用的是IIS 7.5,然後,而不是「自定義錯誤「你會尋找」每下面的圖片.NET錯誤頁」:

enter image description here

這適用於Windows Server 2008和其他較新的Windows SKU的。