代码之家  ›  专栏  ›  技术社区  ›  Mitchel Sellers

ASP.NET模拟和SQL Server可信连接调用

  •  0
  • Mitchel Sellers  · 技术社区  · 17 年前

    Dim impersonationContext As System.Security.Principal.WindowsImpersonationContext
    Dim currentWindowsIdentity As System.Security.Principal.WindowsIdentity
    currentWindowsIdentity = CType(User.Identity, System.Security.Principal.WindowsIdentity)
    impersonationContext = currentWindowsIdentity.Impersonate()
    

    在此之后,我们通过调用以下命令验证应用程序是否在适当的上下文下运行:

    System.Security.Principal.WindowsIdentity.GetCurrent().Name
    

    这将返回用户的正确身份,并且文件访问和其他项目似乎正在使用其帐户。但是,当使用Microsoft Application Data Application Block SqlHelper类调用使用受信任连接的数据库时,“NT AUTHORITY\ANONYMOUS LOGON”用户的身份验证失败。

    有人知道为什么会这样吗?或者更具体地说,我们怎样才能绕过它?

    编辑

    我们从.aspx页面进行模拟调用。

    我们知道上下文标识在这里仍然是正确的。

    之后,“业务逻辑”程序集调用另一个实际执行可信连接调用的程序集。我们无法修改此“数据访问”程序集,此程序集也报告了身份验证异常。

    2 回复  |  直到 17 年前
        1
  •  3
  •   Paul Nearney    17 年前

    我认为@John Sonmez是对的,你在讨论双跳问题。模拟只是故事的一半,您还需要查看委托(假设您的网络使用Kerberos身份验证)。下面的文章对帮助我解决同一问题最有用

    Impersonation and Delegation

    ASP.NET Delegation

        2
  •  0
  •   Dan Esparza    17 年前

    我知道我以前在ASP.NET中使用过模拟(使用C#和访问文件系统),我想知道您是否尝试过包装包含 currentWindowsIdentity.Impersonate()

    所以,它看起来是这样的:

    Using impersonationContext = currentWindowsIdentity.Impersonate() 
    ' Logic here 
    End Using