【问题标题】:Custom Error Handling in Classic ASP经典 ASP 中的自定义错误处理
【发布时间】:2017-11-16 08:38:59
【问题描述】:

我的主要目标:为应用程序添加一个错误处理程序通用页面。

我的应用程序正在使用 Application Pool .Net v 4.5 Classic 为 Classic ASP 和 ASP.net 运行。使用 CustomErrors,我可以使用以下方法处理 .net 页面的错误:

<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>

使用以下链接,我正在尝试为 ASP 页面添加自定义错误处理程序 https://msdn.microsoft.com/en-gb/library/ms524942.aspx

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

我的主要目标是处理 VbScript 运行时/语法错误 500.100,所以我更新了 web.config 中的 HttpErrors 节点为:

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

我在应用程序的根文件夹中有 ASP 错误的处理程序页面:frmErrorPage.asp。 代码:

<%@ 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>

这对我不起作用,我尝试了其他变体但还没有成功。帮助?

【问题讨论】:

  • 在选项显式后移到页面顶部旁边的错误恢复

标签: .net iis vbscript error-handling asp-classic


【解决方案1】:

在 ASP Classic 中创建一个自己的方法/函数,并传递所需的参数,包括行号、页面名称、错误描述以及发送错误电子邮件通知是您在 PROD Evn 中工作。

例如 调用handleError(strScreenName,strScriptName,strFunctionName,err.number,err.Description,"")

函数句柄错误 设置 objASPError = Server.GetLastError
'创建自己的逻辑 结束函数

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-19
    • 1970-01-01
    • 2010-09-27
    • 1970-01-01
    • 1970-01-01
    • 2013-04-13
    • 1970-01-01
    相关资源
    最近更新 更多