这里是我的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