【发布时间】:2012-10-17 18:11:09
【问题描述】:
我正在将 VS2012 与 VB.NET 一起用于 winfowms 应用程序,使用 Active Directory 角色。 以没有权限的用户身份运行程序,尝试启动此表单时出现(预期的)安全异常。
我有一个如下所示的表单:
<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 分钟后”?)程序崩溃。
更新:在任何类型的更多输入后,程序崩溃。我有 debugged the code as the user 没有权限,并且能够捕获抛出的异常 - 显然是不知从何而来。说“调用堆栈只包含外部代码”很奇怪,并显示如下:
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()
这似乎暗示关闭表单很困难?谁能告诉我为什么会抛出这个异常?
【问题讨论】:
标签: winforms exception active-directory code-access-security user-roles