Classic ASP: Capture Errors

Is it possible to fix all 500 errors in classic ASP globally? Maybe something in IIS. I am using II6 at the moment. I like to capture the error message and then save it to the database. I know that this is possible on ASPX pages, but I don’t know exactly how you do it in classic asp.

thanks

+6
source share
4 answers

Yes, create an asp page in which error data will be written to the database, and set this as the 500 handler page in IIS, as shown below.

Use the Server.GetLastError object to get error information in your script handler.

It might be nice to connect to a text file rather than a DB in your 500 handler to provide fault tolerance.

Set Custom 500 Handler in IIS

+13
source

Complementing Jon's answer, use this script to write errors to the log file:

<% 'Set this page up in IIS to receive HTTP 500 errors ''Type' needs to be 'URL' and the URL is eg: '/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 %> 
+5
source

Error handling in classic ASP is a complete pain. You can catch an error when, in your opinion, this will happen using on error resume next , and then check the error code in the next line of code.

Alternatively, you can scan server logs for 500 errors. or configure the 500 Errors page in IIS settings.

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

To add an answer to @Jon Eastwood — if you are using IIS 7.5, instead of “Custom Errors” you will look for “.NET Error Pages” in the image below:

enter image description here

This applies to Windows Server 2008 and other new SKUs for Windows.

0
source

Source: https://habr.com/ru/post/908348/


All Articles