1

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

4

4 回答 4

0

所以我想出的答案是: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
%>
于 2012-07-10T10:22:33.097 回答
0

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

于 2012-07-06T16:45:19.750 回答
0

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

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

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

<%
    Response.Write "<img src=""" & myPhotoUrl & """>"
%>
于 2012-07-08T07:12:19.787 回答
0

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

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

带有 base64 字符串的 HTML 图像标记(数据 URI)

于 2012-07-06T17:09:49.497 回答