這裏是我的Application_OnError事件接收器在global.asax.vb:使用自定義的錯誤沒有得到重定向到自定義錯誤頁 - ASP.Net
Sub Application_OnError(ByVal sender As Object, ByVal e As EventArgs)
Dim innerMostException As Exception = getInnerMostException(Me.Context.Error)
If TypeOf innerMostException Is AccessDeniedException Then
Security.LogAccessDeniedOccurrence(DirectCast(innerMostException, AccessDeniedException))
Dim fourOhThree As Integer = DirectCast(HttpStatusCode.Forbidden, Integer)
Throw New HttpException(fourOhThree, innerMostException.Message, innerMostException)
End If
End Sub
你會看到,如果我們完成了最裏面的異常的類型AccessDeniedException異常我們拋出一個新的HTTPExcpetion與AKA「禁止」
下面是相關的web.config條目403狀態碼:
<customErrors defaultRedirect="~/Application/ServerError.aspx" mode="On">
<error statusCode="403" redirect="~/Secure/AccessDenied.aspx" />
</customErrors>
所以我們正在期待是重定向到t他訪問了AccessDenied.aspx頁面。我們得到是重定向到ServerError.aspx頁面。
我們也嘗試過這樣的:
Sub Application_OnError(ByVal sender As Object, ByVal e As EventArgs)
Dim innerMostException As Exception = getInnerMostException(Me.Context.Error)
If TypeOf innerMostException Is AccessDeniedException Then
Security.LogAccessDeniedOccurrence(DirectCast(innerMostException, AccessDeniedException))
Context.Response.StatusCode = DirectCast(HttpStatusCode.Forbidden, Integer)
End If
End Sub
哪個unsuprisingly也不起作用。
任何想法我們做錯了什麼?
是啊,我想我有點隧道visioned有關通過web.config中的自定義錯誤部分使用重定向,並駁回只是在做一個Server.Transfer的。謝謝您的幫助。 – user129345 2010-03-25 10:20:42