使用UpdatePanel時,我在自定義錯誤頁面中看不到真正的錯誤。在我的Global.asax我有以下代碼:如何在使用UpdatePanel時獲得真正的異常消息?
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
'Get the exception
Dim lastError = Server.GetLastError()
If lastError IsNot Nothing Then
Dim ex As Exception = lastError.GetBaseException()
If ex IsNot Nothing Then
'Log the error
If Log.IsErrorEnabled Then
log4net.ThreadContext.Properties("method") = ex.TargetSite.Name
log4net.ThreadContext.Properties("userId") = User.Current.UserName
Log.Error(ex.Message, ex)
End If
End If
End If
End Sub
如果我查看日誌或設置斷點,我可以看到,我得到一個超時問題。然後,我有以下的代碼到用戶發送到錯誤頁面,並顯示錯誤:
<script language="javascript" type="text/javascript">
function EndRequestHandler(sender, args) {
if (args.get_error() != undefined) {
// Let the framework know that the error is handled,
// so it doesn't throw the JavaScript alert.
args.set_errorHandled(true);
var errorMessage = args.get_error().message.replace(/</gi, "<").replace(/>/gi, ">");
// If there is, show the custom error.
window.location = _root + 'ShowError.aspx?error=' + encodeURI(errorMessage)
}
}
</script>
但我從args.get_error(得到的錯誤)是這個:
Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500
我需要做什麼才能使錯誤頁面發生超時錯誤?
另外,我有customErrors mode = 「開」,如果我添加defaultRedirect =「ShowError.aspx」狀態代碼從500更改爲0,但我仍然收到錯誤。 – adam0101