我希望做如下......提供的網頁開發者可以重定向到提供發生錯誤...就像一個VB錯誤連接無法打開或對象找不到...或數據庫錯誤提出...但由於我將重定向到一個子頁面實際上並沒有重定向...是否有可能我不能從一個子重定向?看起來很奇怪。傳統的ASP - Response.Redirect的一個子 - 錯誤處理
運行的是引發錯誤
Dim cmd
Set cmd = Server.CreateObject("ADODB.Command")
cmd.ActiveConnection = con
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "spReturnDBException"
cmd.Execute
,呼叫處理錯誤的功能,設置了一些會話PARMS並重定向如果neccessary
HandleErrors con _
, Request.ServerVariables("PATH_INFO") _
, "An error occurred while trying to save sessions." _
, "Actual Error: " + Err.Description + " EmpNo: " + Session("EmpNo") _
+ ". QueryString: " + Request.Querystring _
, 0
這被稱爲子存儲過程。
sub HandleErrors(connection, WebPagePath, GenericErrorMessage, DebugInfo, Severity)
//Check for vb errors
if Err.Number <> 0 Then
Session("WebPagePath") = WebPagePath
Session("SafeErrorMessage") = GenericErrorMessage 'Session("SafeErrorMessage") + "A connection was dropped while trying to complete sessions."
Session("DebugInfo") = DebugInfo ' Err.Description
Session("LineNo") = Err.Line
Session("StackTrace") = ""
Session("Severity") = Severity
response.redirect("Error.asp")
//error occurs
elseif connection.Errors.count <> 0 then
response.write("a database error occurred.")
// Store safe error message/# in session
Session("WebPagePath") = WebPagePath
Session("SafeErrorMessage") = GenericErrorMessage 'Session("SafeErrorMessage") + "An error has occurred while trying to save sessions."
Session("DebugInfo") = DebugInfo '"Some extra added debug info from the webpage"
Session("LineNo") = 0
Session("StackTrace") = ""
Session("Severity") = Severity
Dim objError
for each objError in connection.Errors
// Store safe error number in session
Session("SafeErrorNumbers") = Session("SafeErrorNumbers") + objError.Description
if connection.Errors.Count > 1 then
Session("SafeErrorNumbers") = Session("SafeErrorNumbers") + "|"
end if
next
response.Redirect("Error.asp")
end if
Err.Clear
end sub
您是否收到錯誤? – Robert 2012-01-04 16:24:40
@Robert如果我關閉「在錯誤恢復下一步」我得到的過程中提出的錯誤...這是我所期望的。如果我設置「On error resume next」,那麼重定向就不會發生,我最終坐在我的原始頁面上,沒有任何反應。 – 2012-01-04 16:37:34
你可以改變一個函數,並將重定向頁面返回到調用頁面,並讓該頁面做'response.redirect()' – Robert 2012-01-04 16:46:23