【发布时间】:2017-05-14 02:48:36
【问题描述】:
我有一个 ASP.NET 4.0 Intranet 站点,它使用 Windows 身份验证并且通常作为默认 IIS 用户运行。我想冒充经过身份验证的用户并代表他们行事。具体来说,如果该用户是域管理员,我希望他们能够监控在多个服务器上运行的服务,启动和停止这些服务,并重新启动这些服务器,所有这些都来自 Intranet 页面。
到目前为止,我可以切换上下文以模拟经过身份验证的用户,并且可以检查用户的 AD 组以确定他们是否是域管理员。但是当我尝试获取其他服务器上运行的服务的状态时,出现以下错误:
无法在计算机“MyServer”上打开服务控制管理器。这 操作可能需要其他权限。 ---> System.ComponentModel.Win32Exception:访问被拒绝
它在本地 Visual Studio 中运行良好。但内网站点部署到内部网络服务器时则不然。
在Page_Load我这样做:
'Switch from IIS User to the currently authenticated Admin user
Dim impersonationContext As WindowsImpersonationContext = Nothing
Dim authenticatedIdentity As WindowsIdentity = DirectCast(HttpContext.Current.User.Identity, WindowsIdentity)
impersonationContext = authenticatedIdentity.Impersonate()
然后在GridView 的RowDataBound 事件中,我这样做:
'Check if service exists and is running
Dim arrServices() As ServiceController = ServiceController.GetServices(machineName)
If Not arrServices.Any(Function(o) o.ServiceName = SERVICE_NAME) Then
' Service is missing...
Else
Dim oServiceController As New ServiceController(SERVICE_NAME, machineName)
If oServiceController.Status = ServiceControllerStatus.Running Then
' Service is running...
Else
' Service has stopped...
End If
End If
如何在此 Intranet 站点上使用 Windows 身份验证代表用户管理其他服务器?
【问题讨论】:
-
代码并不仅仅只是默默地停止处理。也许您应该在问题中显示相关代码。
-
@mason 请查看我修改后的问题。我有一个抑制错误的尝试捕获。请立即查看真正的错误消息。
标签: asp.net windows-authentication impersonation