これがglobal.asax.vbのApplication_OnErrorイベントシンクです。
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タイプの最も内側の例外がある場合、ステータスコード403AKA'forbidden'の新しいHTTPExcpetionをスローすることがわかります。
関連するweb.configエントリは次のとおりです。
<customErrors defaultRedirect="~/Application/ServerError.aspx" mode="On">
<error statusCode="403" redirect="~/Secure/AccessDenied.aspx" />
</customErrors>
したがって、私たちが期待しているのは、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
当然のことながら、どちらも機能しません。
私たちが間違っていることについて何か考えはありますか?