2
votes

My Main Aim: Add a Error handler Generic Page for Application.

My Application is running for both Classic ASP and ASP.net using Application Pool .Net v 4.5 Classic. Using CustomErrors, I am able to handle errors for .net Pages using:

<customErrors allowNestedErrors="true" defaultRedirect="~/ErrorPage.aspx" mode="On">
<error statusCode="404" redirect="~/ErrorPage.aspx?msg=404" />
<error statusCode="500" redirect="~/ErrorPage.aspx?msg=500" />
</customErrors>

Using the following link,I am trying to add custom error handler for ASP Pages https://msdn.microsoft.com/en-gb/library/ms524942.aspx

https://msdn.microsoft.com/en-us/library/ms525983(v=vs.90).aspx

My Main aim is handle VbScript runtime/syntax error 500.100, so I have updated HttpErrors node in web.config as:

<httpErrors errorMode="Custom">
        <error statusCode="500" subStatusCode="100" path="~/frmErrorPage.asp" responseMode="Redirect" />
</httpErrors>

I have handler page for ASP Errors: frmErrorPage.asp in the root folder of the application. Code:

<%@ Language=VBScript %>
<% Option Explicit %>
<% Response.CacheControl = "no-cache" %>
<% Response.AddHeader "Pragma", "no-cache" %>
<% Response.Expires = -1 %>

<% ' VI 6.0 Scripting Object Model Enabled %>
<!--#include file="_ScriptLibrary/pm.asp"-->
<script ID="serverEventHandlersVBS" LANGUAGE="vbscript" RUNAT="Server">

dim objASPError

Sub thisPage_onenter()

ShowErrorInformation()

 end sub

Function ShowErrorInformation()
On Error Resume Next
Set objASPError = Server.GetLastError
Response.Write Server.HTMLEncode(objASPError.Category)
If Len(CStr(objASPError.ASPCode)) > 0 Then
    Response.Write Server.HTMLEncode(", " & objASPError.ASPCode)
End If
Response.Write Server.HTMLEncode(" (0x" & Hex(objASPError.Number) & ")" ) & "<br>"
If Len(CStr(objASPError.ASPDescription)) > 0 Then 
    Response.Write Server.HTMLEncode(objASPError.ASPDescription) & "<br>"
ElseIf Len(CStr(objASPError.Description)) > 0 Then 
    Response.Write Server.HTMLEncode(objASPError.Description) & "<br>" 
End If
end function

</script>

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>

<LINK REL="stylesheet" TYPE="text/css" HREF="_Themes/expeditn/THEME.CSS" VI6.0THEME="Expedition">
<LINK REL="stylesheet" TYPE="text/css" HREF="_Themes/expeditn/GRAPH0.CSS" VI6.0THEME="Expedition">
<LINK REL="stylesheet" TYPE="text/css" HREF="_Themes/expeditn/COLOR0.CSS" VI6.0THEME="Expedition">
<LINK REL="stylesheet" TYPE="text/css" HREF="_Themes/expeditn/CUSTOM.CSS" VI6.0THEME="Expedition">

</HEAD>
<BODY onload="return window_onload()">

</BODY>
</HTML>

This is not working for me, I have tried other variations but no success yet.Help ?

1
Move On Error Resume Next to the top of your page after Option Explicitmjw

1 Answers

0
votes

Create a own method/function in ASP Classic and pass required parameter with line no., page name, Error Description with sending Error Email notification is you are working in PROD Evn.

For Example call handleError (strScreenName,strScriptName,strFunctionName,err.number,err.Description,"")

Function handleError Set objASPError = Server.GetLastError
'Create your own logic End Function