在经典 ASP/VBScript 应用程序中通过 LDAP 访问员工 ID [英] Accessing Employee ID via LDAP in a Classic ASP/VBScript application

查看:16
本文介绍了在经典 ASP/VBScript 应用程序中通过 LDAP 访问员工 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个旧的 ASP/VBScript 应用程序,我正在维护/升级它,它目前使用旧的/折旧的方法来收集配置文件信息 - 如下所示:

I've got an older ASP/VBScript app that I'm maintaining/upgrading and its currently using the older/depreciated means of gathering profile information - like below:

strNTUser = Request.ServerVariables("AUTH_USER")
strNTUser = replace(strNTUser, "", "/")
Set strNTUserInfo = GetObject("WinNT://"+strNTUser)
'You get the idea'

当我只需要全名和描述时,这很好.现在我需要访问一些额外的配置文件信息,但我需要使用 LDAP 而不是 WinNT.我一直在谷歌上搜索,直到我失明,但对于我的生活,我似乎无法全神贯注地通过 LDAP 进行连接并获取我需要的信息.

When all I needed was the full name and the description, this was fine. Now I need to access some additional profile information, but I need to use LDAP instead of WinNT. I've Google'd till I was blind, but for the life of me I just can't seem to wrap my brain around connecting via LDAP and getting the info that I need.

如何根据 AUTH_USER 获取名字、姓氏和员工 ID?

What do I need to do to get the First Name, Last Name, and Employee ID based on the AUTH_USER?

更新:我从一开始就认为需要 ADSI 或一些类似的接口,但我显然是一个 ADIdiot 并且没有得到任何有用的提示 - 更不用说帮助 - 从我发现的任何东西MSDN 或 TechNet.更明确的帮助会很好......

Update: I figured from the outset that ADSI or some similar interface would be required, but I am apparently an ADIdiot and am getting no useful hint - let alone help - from anything I have found on MSDN or TechNet. More explicit help would be nice...

推荐答案

我确信可能有更有效的方法可以做到这一点,但这是我经过多次搜索、尝试和咬牙切齿后最终使用的代码...

I'm sure there's probably a little more efficient way of doing this, but here's the code I ended up using after much searching, trying, and gnashing of teeth...

Dim strNTUser, strUser, strDN, strRootTDSE
Dim objRootDSE, objConnection, objCommand, objRecordSet, objUser, objNTUserInfo

strNTUser = Request.ServerVariables("AUTH_USER")
strUser = Mid(strNTUser,(instr(1,strNTUser,"")+1),len(strNTUser))

Set objConnection = Server.CreateObject("ADODB.Connection")
Set objCommand = Server.CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

'objCommand.Properties("Page Size") = 1000'
objCommand.Properties("Searchscope") = 2 'ADS_SCOPE_SUBTREE 

Set objRootDSE = GetObject("LDAP://rootDSE")
strRootTDSE = objRootDSE.Get("defaultNamingContext")
Set objRootDSE = Nothing

objCommand.CommandText = _
    "SELECT distinguishedName FROM 'LDAP://" & strRootTDSE & "' " & _
        "WHERE objectCategory='user' AND sAMAccountName = '" & strUser & "'" 

Set objRecordSet = objCommand.Execute

If Not objRecordSet.BOF Then objRecordSet.MoveFirst
If Not objRecordSet.EOF Then
    strDN = objRecordSet.Fields("distinguishedName").Value
End If

Set objConnection = Nothing
Set objCommand = Nothing
Set objRecordSet = Nothing

Set objUser = GetObject("LDAP://" & strDN)
'I can now use objUser to get the details'

我很乐意接受任何重构的代码,这也是我现在必须将网站降低到基本身份验证"以使其正常工作的原因.

I'll happily accept any refactored code, and a reason why I now have to lower the site to "Basic Authentication" in order for this to work.

附带说明一下,我尝试尽可能少地进行硬编码,以便将其发送回我从中获取原始代码的开源项目.

As a side note, I've tried to hard-code as little as possible so I can send it back to the open source project I got the original code from.

这篇关于在经典 ASP/VBScript 应用程序中通过 LDAP 访问员工 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆