【问题标题】:Manage machines on the network using an ASP.NET intranet site with Windows authentication使用具有 Windows 身份验证的 ASP.NET Intranet 站点管理网络上的计算机
【发布时间】: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()

然后在GridViewRowDataBound 事件中,我这样做:

'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


【解决方案1】:

事实证明,您可以获得基本上两个级别的 Windows 身份令牌。

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-03
    • 2017-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-13
    相关资源
    最近更新 更多