0

Active Directoryの役割を使用して、winfowmsアプリにVB.NETでVS2012を使用しています。権限のないユーザーとしてプログラムを実行すると、このフォームを起動しようとすると(予期される)セキュリティ例外が発生します。

私は次のようなフォームを持っています:

<PrincipalPermission(SecurityAction.Demand, Role:=Security.Roles.ADMINISTRATORS)> _
<PrincipalPermission(SecurityAction.Demand, Role:=Security.Roles.CORRECTIVE_ACTION_EDITORS)> _
<PrincipalPermission(SecurityAction.Demand, Role:=Security.Roles.GRIEVANCE_EDITORS)> _
<PrincipalPermission(SecurityAction.Demand, Role:=Security.Roles.ABOLISHMENT_EDITORS)> _
Public Class EmployeeInformationForm
...
End Class

コードの呼び出しは次のようになります。

    Private Sub SendEmployeeIDToEmployeeInformationForm(ByVal ID_in As String, ByVal employeeRecord_in As String)
    ...
        If Not formFound Then
            ' Create a new instance of the child form.
            Dim ChildForm As New EmployeeInformationForm(ID_in, employeeRecord_in) ' ** throws expected security exception here**
            Try
                ' Make it a child of this MDI form before showing it.
                ChildForm.MdiParent = Me.MdiParent
        ...
                ChildForm.Show()
            Catch ex As Exception
                ChildForm.Close()
                Throw
            End Try
        End If

15回または16回試行した後(または変数が「約1分後」である可能性がありますか?)、プログラムがクラッシュします。 更新:あらゆる種類の入力が増えると、プログラムがクラッシュします。私は許可のないユーザーとしてコードをデバッグし、スローされた例外をキャプチャすることができました-どうやらどこからともなく。「コールスタックには外部コードのみが含まれている」と言うのは非常に奇妙で、次のように表示されます。

This thread is stopped with only external code frames on the call stack. External code frames are typically from framework code but can also include other optimized modules which are loaded in the target process.

Call stack with external code

mscorlib.dll!System.Security.Permissions.PrincipalPermission.ThrowSecurityException()
mscorlib.dll!System.Security.Permissions.PrincipalPermission.Demand()
mscorlib.dll!System.Security.PermissionSet.DemandNonCAS()
[Native to Managed Transition]
[Managed to Native Transition]
OHRC Database.exe!OHRC_Database.EmployeeInformationForm.Dispose(Boolean disposing)
System.dll!System.ComponentModel.Component.Finalize()

フォームを閉じるのに苦労していることを意味しているようですか?なぜこの例外がスローされるのか誰かに教えてもらえますか?

4

1 に答える 1

2

例外はファイナライズスレッドからスローされており(例外スタックトレースのFinalize()呼び出しがそのヒントです)、そのスレッドのユーザーIDにも適切なアクセス許可がありません。詳細については、 http://msmvps.com/blogs/calinoiu/archive/2006/01/07/why-is-my-application-coughing-up-a-securityexception-after-my-code-stops-running.aspxを参照してください。詳細と修正。

HTH、ニコール

于 2012-10-18T01:35:25.720 に答える