来自AD的经典ASP组织结构

时间:2015-09-04 11:54:38

标签: asp-classic active-directory ldap

我有以下代码从Active Directory中提取组织结构:

<%@ Language="VBScript"%>
<% response.Buffer = True
 'Define the AD OU that contains our users
 dim department
 %>
 <!--#include file="includes/functions.asp"-->
 <!--#include file="includes/display.asp"-->
 <h1>Organisational Structure</h1>
 <div class="commandspace">
 <p class="infotext">The org structure can be viewed with or without staff, indented or left justified.</p>
 </div>
 <div class="Structure_Item_1">
 <% 
 ADUser = "LDAP://OU=Staff,OU=Users,DC=DOMAIN,DC=internal"
 ' Make AD connection and run query
 Set objCon = Server.CreateObject("ADODB.Connection")
 objCon.provider ="ADsDSOObject"
 objCon.Properties("User ID") = "DOMAIN\example_user"
 objCon.Properties("Password") = "password"
 objCon.Properties("Encrypt Password") = TRUE
 objCon.open "Active Directory Provider"
 Set objCom = CreateObject("ADODB.Command")
 Set objCom.ActiveConnection = objCon
 objCom.CommandText ="select company FROM '"& ADUser &"' where company ='*' ORDER by company ASC"
 Set objRS = objCom.Execute
 ' Loop over returned recordset and output HTML
 Do While Not objRS.EOF Or objRS.BOF
      Response.Write "<div id='Structure_Item_Field'>" & objRS("company") & "</div>"
      Set objCom = CreateObject("ADODB.Command")
      Set objCom.ActiveConnection = objCon
      objCom.CommandText ="select department FROM '"& ADUser &"' where company ='*" & objRS("company") & "*' ORDER BY company ASC"
      Set department = objCom.Execute
      ' Loop over returned recordset and output HTML
           Do While Not department.EOF Or department.BOF
           Response.Write "&nbsp;&nbsp;&nbsp;&nbsp;" & department("department") & "<br>"
           '&nbsp is the HTML entity of a space character. I put &nbsp four times so that the department is indented four spaces
           Set objCom = CreateObject("ADODB.Command")
           Set objCom.ActiveConnection = objCon
           objCom.CommandText ="select givenName, sn FROM '"& ADUser &"' where department ='*" & department("department") & "*' ORDER by givenName ASC"
           Set names = objCom.Execute
           Do While Not names.EOF Or names.BOF

                Response.Write "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" & names("givenName") & " " & names("sn") & "<br>"
                names.MoveNext
                Response.Flush
           Loop
           department.MoveNext
           Response.Flush
      Loop

      objRS.MoveNext
      Response.Flush
 Loop
 ' Clean up
 objRS.Close
 objCon.Close
 Set objRS = Nothing
 Set objCon = Nothing
 Set objCom = Nothing
 %>

请原谅我的无知,但似乎很慢,我不知道为什么。我不确定我需要做些什么才能提高性能。      

0 个答案:

没有答案