Active Directory 查询 ASP VB .Net 仅适用于受信任的站点

发布于 2024-10-11 14:44:00 字数 746 浏览 4 评论 0原文

我有一个用 Visual Basic .Net 编写的 ASP .Net Web 应用程序,在 Windows Server 2003 (IIS 6) 上运行,其工作方式与 如何从 Web 应用程序中的客户端计算机获取 AD 凭据?

用户访问我们的 Intranet 页面,它使用 Windows 身份验证来识别用户。然后,应用程序在 Active Directory 中查找该用户并获取该用户的 IpPhone 的属性值。这个号码就是我们用于员工 ID 的号码。

在 IE8 中,我可以访问该站点,Windows Auth 会提示我,它似乎可以工作,但应用程序无法获取我的 Active Directory 用户“IP 电话”值(也称为我的员工编号)。如果我将 URL 添加到受信任的站点,应用程序将成功获取我的员工 ID。

这没什么大不了的,除非它在每个浏览器(FireFox、Safari 和 Chrome)中都会这样做。我找到了 Firefox 的解决方法(ntlm-authenticate,google 'about config' for firefox)。但是,这个应用程序不需要位于受信任的站点中,并且我相信,如果我可以在不位于受信任的站点中的情况下使其正常工作,它将在所有浏览器中运行。

有人知道发生了什么事吗?提前致谢。

I have a ASP .Net web appliaction written in Visual Basic .Net running on Windows Server 2003 (IIS 6) that works like the one described in How to grab AD credentials from client machine in a web application?

A user access our Intranet page and it uses Windows Authentication to identify the user. The application then looks up that user in Active Directory and grabs the attribute value for that user's IpPhone. This number is what we use for Employee ID's.

In IE8 I can access the site and Windows Auth prompts me and it appears to work but the application is unable to get my Active Directory user "IP Phone" value (AKA my Employee Number). If I add the URL to Trusted Sites, the application works grabs my Employee ID successfully.

That wouldn't be a big deal except it does this in every browser (FireFox, Safari, and Chrome). I found a workaround for Firefox (ntlm-authenticate, google 'about config' for firefox). However this app shouldn't need to be in Trusted Sites, and I believe if I can get this to work without being in Trusted Sites it will work in all browsers.

Does anyone have any idea whats going on? Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌吟 2024-10-18 14:44:00

看看下面截图中的设置。自动登录是指通过 Internet Explorer 访问资源时使用 Windows 身份验证。换句话说,如果您访问目录中服务器上的网页,您在计算机上登录所使用的凭据将自动传递到您正在访问的服务器。

由于某种我不知道的原因,这些凭据通常也会传递到受信任的站点。我不知道为什么会这样,但我已经看到这种行为,足以有信心地说出来。

此功能仅在 IE 中可用(您为 Firefox 找到的解决方法除外),并且不适用于其他浏览器,除非您找到类似的解决方法。

更好的解决方案是在代码中指定用户名和密码,如下所示:

http ://msdn.microsoft.com/en-us/library/wh2h7eed.aspx

这将执行搜索并传递用户名和密码,而不是依赖于 Windows 集成安全性。

alt text

我这里有一个工作代码片段,用于根据我们域中的用户名获取电子邮件,您可以对其进行修改您的需求:

Public Function GetEmailFromUserName(ByVal UserID As String) As String
    Dim ReturnValue As String = ""


    Dim myAD As New System.DirectoryServices.DirectoryEntry("LDAP://mydomain", System.Configuration.ConfigurationManager.AppSettings("adsearchname"), System.Configuration.ConfigurationManager.AppSettings("adsearchpwd"))
    Dim searcher As New System.DirectoryServices.DirectorySearcher(myAD)
    searcher.Filter = ("(anr= " & UserID & ")")
    searcher.PropertiesToLoad.Add("mail")
    For Each myResult As System.DirectoryServices.SearchResult In searcher.FindAll()
        For Each Key As String In myResult.Properties.PropertyNames
            If InStr(myResult.Properties.Item(Key).Item(0), "@") Then
                ReturnValue = myResult.Properties.Item(Key).Item(0)
            End If
        Next
    Next

    Return ReturnValue
End Function

Take a look at the setting in the screenshot below. The automatic logon refers to using your Windows authentication as you access resources via Internet Explorer. In other words, if you access a web page on a server in your directory, the credentials that you logged in on your machine with are automatically passed to the server you're accessing.

The credentials are generally, for some reason unknown to me, passed along to trusted sites as well. I don't know why this is, but I've seen this behavior enough to be confident stating it.

This feature is only available in IE, except for the workaround you found for Firefox, and will not work in other browsers, unless you find similar workarounds.

A better solution would be to specify the username and password in code as shown here:

http://msdn.microsoft.com/en-us/library/wh2h7eed.aspx

This performs a search and passes along a username and password, rather than relying on the Windows Integrated security.

alt text

I have a working snippet of code here for getting an email based on username in our domain, that you can modify for your needs:

Public Function GetEmailFromUserName(ByVal UserID As String) As String
    Dim ReturnValue As String = ""


    Dim myAD As New System.DirectoryServices.DirectoryEntry("LDAP://mydomain", System.Configuration.ConfigurationManager.AppSettings("adsearchname"), System.Configuration.ConfigurationManager.AppSettings("adsearchpwd"))
    Dim searcher As New System.DirectoryServices.DirectorySearcher(myAD)
    searcher.Filter = ("(anr= " & UserID & ")")
    searcher.PropertiesToLoad.Add("mail")
    For Each myResult As System.DirectoryServices.SearchResult In searcher.FindAll()
        For Each Key As String In myResult.Properties.PropertyNames
            If InStr(myResult.Properties.Item(Key).Item(0), "@") Then
                ReturnValue = myResult.Properties.Item(Key).Item(0)
            End If
        Next
    Next

    Return ReturnValue
End Function
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文