Asp-Classic
經典 ASP:擷取錯誤
是否可以在全域級別擷取 Classic ASP 中的所有 500 個錯誤?也許在 IIS 中。我目前正在使用 II6。我喜歡擷取錯誤消息,然後將其儲存在數據庫中。我知道它在 ASPX 頁面中是可能的,但不知道你在經典 asp 中的具體表現。
謝謝
是的,創建一個將錯誤詳細資訊記錄到數據庫的 asp 頁面,並將其設置為 IIS 中的 500 處理程序頁面,如下所示。
使用 Server.GetLastError 對像在處理程序腳本中獲取錯誤的詳細資訊。
在 500 處理程序中記錄到文本文件而不是數據庫以提高彈性可能是個好主意。
補充 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 %>
