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

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

问题描述

我有一个较旧的ASP / VBScript中的应用程序,我维护/升级其目前使用的是旧/德preciated收集的个人资料信息的方式 - 象下面这样:

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。我Google'd直到我是盲人,但对我的生活我似乎无法环绕通过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...

推荐答案

我敢肯定,可能有这样做的一点点更有效的方式,但这里的code我结束了使用后一番搜索,尝试,咬牙切齿......

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'

我将愉快地接受任何重构code和一个原因,我现在为了这个工作,以降低该网站为基本身份验证。

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.

作为一个方面说明,我试图硬code尽可能少这样我就可以发回的开源项目,我从原来的code。

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.

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

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