Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用具有Windows身份验证的ASP.NET intranet站点管理网络上的计算机_Asp.net_Windows Authentication_Impersonation - Fatal编程技术网

使用具有Windows身份验证的ASP.NET intranet站点管理网络上的计算机

使用具有Windows身份验证的ASP.NET intranet站点管理网络上的计算机,asp.net,windows-authentication,impersonation,Asp.net,Windows Authentication,Impersonation,我有一个ASP.NET 4.0 intranet站点,它使用Windows身份验证,通常作为默认IIS用户运行。我想冒充经过身份验证的用户并代表他们行事。特别是,如果该用户是域管理员,我希望他们能够监视在多个服务器上运行的服务,启动和停止这些服务,并重新启动这些服务器,所有这些都可以从intranet页面进行 到目前为止,我可以切换上下文来模拟经过身份验证的用户,并且可以检查用户的广告组以确定他们是否是域管理员。但是,当我尝试获取其他服务器上运行的服务的状态时,会出现以下错误: 无法在计算机“M

我有一个ASP.NET 4.0 intranet站点,它使用Windows身份验证,通常作为默认IIS用户运行。我想冒充经过身份验证的用户并代表他们行事。特别是,如果该用户是域管理员,我希望他们能够监视在多个服务器上运行的服务,启动和停止这些服务,并重新启动这些服务器,所有这些都可以从intranet页面进行

到目前为止,我可以切换上下文来模拟经过身份验证的用户,并且可以检查用户的广告组以确定他们是否是域管理员。但是,当我尝试获取其他服务器上运行的服务的状态时,会出现以下错误:

无法在计算机“MyServer”上打开服务控制管理器。这 操作可能需要其他权限。--> System.ComponentModel.Win32异常:访问被拒绝

它在本地VisualStudio中运行良好。但当内部网站点部署到内部web服务器时,情况并非如此

页面\u 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()
'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
然后在
GridView
RowDataBound
事件中,我执行以下操作:

'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()
'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身份验证代表用户管理其他服务器?

事实证明,您可以获得两个级别的Windows标识令牌

在intranet站点上使用Windows身份验证时自动获得的身份验证有助于针对AD进行身份验证并获取用户的AD组。切换到模拟此标识时,您可以作为经过身份验证的Windows用户访问web服务器上的本地资源,但无法开始访问运行intranet站点的web服务器之外的网络资源


要获得网络访问,您需要使用Windows登录Win32 API。您需要执行“交互式”级别的登录,并从该登录中获取令牌。然后可以通过网络模拟用户。因此,您需要的是用户的密码,而不仅仅是ASP.NET在请求对象中提供的令牌。

代码实际上并不只是静默地停止处理。也许你应该在问题中显示相关代码。@mason请看我修改后的问题。我尝试了一次捕捉,以抑制错误。现在请查看真正的错误消息。