我的主要目標:爲應用程序添加錯誤處理程序通用頁面。經典ASP中的自定義錯誤處理
我的應用程序使用Application Pool .Net v 4.5 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>
這不是爲我工作,我已經嘗試過其他的變化,但沒有成功yet.Help?
移動錯誤恢復在顯示選項後顯示在頁面頂部 – mjw