0

これが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

当然のことながら、どちらも機能しません。

私たちが間違っていることについて何か考えはありますか?

4

1 に答える 1

0

Application_Errorアプリケーションで処理されないエラーをキャッチすることを目的としています。それが発生したとき、エラーはすでに発生しており、すべてがそのエラーに関するものです。内部からエラーをスローした場合Application_Error、実際には「エラーハンドラにエラーがあります」と言っています。代わりServer.Transferに、適切なページに移動します。すべてのリダイレクトロジックをweb.configに保持したい場合は、customErrorsセクションを解析してリダイレクト先を特定する方法に関するこの記事を参照してください。

これはすべて言った、そして私はこれを試していませんが、あなたは電話をしてみることができますServer.ClearError()

            Dim Ex = Server.GetLastError()
            Server.ClearError()
            Throw New HttpException(System.Net.HttpStatusCode.Forbidden, Nothing, Ex)

私が上で言ったことのためにそれがうまくいくとは思わないが、それは試してみる価値がある。

于 2010-03-24T20:27:22.607 に答える