【问题标题】:how to display photo from active directory in classic asp如何在经典asp中显示活动目录中的照片
【发布时间】:2012-07-10 18:28:06
【问题描述】:

如何在经典 asp 中显示活动目录中的照片? 我可以登录到我们的 AD 并从 calssic asp 页面查询用户名电话等。缩略图照片字段只返回一个字符串,请问如何格式化以在经典 asp 中显示照片?

【问题讨论】:

    标签: asp-classic active-directory photos


    【解决方案1】:

    如果我正确理解您的问题,您将使用FileSystemObject 获取二进制图像文件,并在返回图像数据时使用response.contenttype = "image/jpeg",以便将内容呈现为图像。

    【讨论】:

    • 感谢 cmets。我有一个解决方法(如下),它将图片加载到 iframe 内的页面中。第 1 页使用用户名调用它以作为查询字符串进行查询(下面的 req )。 XXX 应替换为有权读取 AD 中所有用户数据的用户名和密码。我现在唯一的问题是图像在 IE 中显示为白色边框。
    • 设置 objDomain = 无设置 con = Server.CreateObject("ADODB.Connection") con.provider ="ADsDSOObject" con.Properties("用户 ID") = "XXXXXXXXXXXXXXX" con.Properties(" Password") = "XXXXXXXXXXXXXXXXX" con.Properties("Encrypt Password") = False con.open "Active Directory Provider" Set Com = CreateObject("ADODB.Command") Set Com.ActiveConnection = con Com.CommandText ="select thumbnailPhoto FROM 'GC://"+objADsPath+"' where sAMAccountname='"+strUsername+"'" 设置 rs = Com.Execute Response.Expires = 0 ntin Response.Buffer = TRUE Response.Clear
    • Response.ContentType = "image/jpeg" '#### 假设你的图片是 jpegs 如果不是 rs.eof 那么 Response.BinaryWrite rs("thumbnailPhoto") else response.write "image for " & strUsername & " Not found" end if rs.Close con.Close Set rs = Nothing Set con = Nothing %>
    • 一项改进:将 iframe 替换为
    【解决方案2】:

    您还可以将照片内嵌在图像中:

    ...img src=[图片的base64表示]>...

    HTML image tag with base64 string (data URI)

    【讨论】:

      【解决方案3】:

      您可以通过使用 html img 标签来做到这一点。例如:

      <img src="<%=myPhotoUrl%>">
      

      在asp代码块中,必须声明为:

      <%
          Response.Write "<img src=""" & myPhotoUrl & """>"
      %>
      

      【讨论】:

        【解决方案4】:

        所以我想出的有效答案是: strUsername = request.querystring("req") strUserRole = request.querystring("rol")

        Set objDomain = GetObject ("GC://rootDSE")
        objADsPath = objDomain.Get("defaultNamingContext")
        Set objDomain = Nothing
        Set con = Server.CreateObject("ADODB.Connection")
        con.provider ="ADsDSOObject"
        con.Properties("User ID") = "XXXXXXXXXXX"
        con.Properties("Password") = "XXXXXXXXXXXXXXX"
        con.Properties("Encrypt Password") = False
        con.open "Active Directory Provider"
        Set Com = CreateObject("ADODB.Command")
        Set Com.ActiveConnection = con
        Com.CommandText ="select name,telephonenumber,mail,thumbnailPhoto, Department, title FROM 'GC://"+objADsPath+"' where sAMAccountname='"+strUsername+"'"
        
        Set rs = Com.Execute
        if not rs.eof then
         tmpphoto=rs("thumbnailPhoto")
         tmpdept=rs("Department")
         tmptitle=rs("title") 
         name=rs("name")
         telephonenumber=rs("telephonenumber")
         mail=rs("mail") 
         NameArr = Split(name, " ")
         cname = NameArr(0)
         sname = NameArr(1)
        rs.Close
        con.Close
        Set rs = Nothing
        Set con = Nothing
        
         %>
         <div id="card"><img src="badge.jpg"  width="100%"/>
        <div id="personname"><%=cname & " " & sname%></div>
        <div id="persongroup"><%=tmptitle%></div>
        <div id="persondept"><%=tmpdept%></div>
        <div id="personrole"><%=strUserRole%></div>
        <div id="personimage">  
            <img src="getaduserimage.asp?req=NAME.SURNAME" width="100" height="100" frameborder="0" scrolling="no" />
        
        </div>
        <div id="logoimage"><img src="OUR_logo_white_small.png"  width="100"/></div>
        <%
         else 
           cname = strUsername & " Not found"
        end if
        
        
        %>
        
        <% 'getaduserimage.asp file contains:
        strUsername = request.querystring("req")
        Set objDomain = GetObject ("GC://rootDSE")
        objADsPath = objDomain.Get("defaultNamingContext")
        Set objDomain = Nothing
        Set con = Server.CreateObject("ADODB.Connection")
        con.provider ="ADsDSOObject"
        con.Properties("User ID") = "xxxxxx"
        con.Properties("Password") = "xxxxxxxx"
        con.Properties("Encrypt Password") = False
        con.open "Active Directory Provider"
        Set Com = CreateObject("ADODB.Command")
        Set Com.ActiveConnection = con
        Com.CommandText ="select thumbnailPhoto FROM 'GC://"+objADsPath+"' where sAMAccountname='"+strUsername+"'"
        
        Set rs = Com.Execute
        Response.Expires = 0  
        Response.Buffer = TRUE  
        Response.Clear  
        Response.ContentType = "image/jpeg" 
        '#### Assuming your images are jpegs 
        if not rs.eof then
        Response.BinaryWrite rs("thumbnailPhoto")  
        else 
           response.write "image for " &  strUsername & " Not found"
        end if
        rs.Close
        con.Close
        Set rs = Nothing
        Set con = Nothing
        %>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-08-25
          相关资源
          最近更新 更多