2012-07-06 33 views
1

如何在經典asp中顯示活動目錄中的照片? 我可以登錄到我們的AD並從一個靜態頁面查詢用戶名電話等。縮略圖照片字段只是返回一個字符串,我該如何格式化以便在經典的asp中以照片方式顯示照片?如何在經典asp中顯示活動目錄中的照片

回答

0

如果我正確理解您的問題,您將使用FileSystemObject獲取二進制映像文件,並在返回圖像數據時使用response.contenttype = "image/jpeg",以便將內容呈現爲圖像。

+0

感謝您的意見。我有一個工作(下),它將圖片加載到iframe中的頁面中。第1頁使用用戶名稱來查詢查詢字符串(請參閱下面的內容)。應該用有權讀取AD中所有用戶數據的用戶名和密碼替換XXX。我現在唯一的問題是圖像在IE中以白色邊框顯示。 <%strUsername = request.querystring(「req」)Set objDomain = GetObject(「GC:// rootDSE」)objADsPath = objDomain.Get(「defaultNamingContext」) '###續... – Richard 2012-07-10 09:19:17

+0

Set objDomain = Nothing Set CON =的Server.CreateObject( 「ADODB.Connection」) con.provider = 「ADsDSOObject」 con.Properties( 「用戶ID」)= 「XXXXXXXXXXXXXXX」 con.Properties( 「密碼」)= 「XXXXXXXXXXXXXXXXX」 CON。屬性(「加密密碼」)=假 con.open「Active Directory Provider」 Set Com = CreateObject(「ADODB.Command」) Set Com.ActiveConnection = con Com.CommandText =「select thumbnailPhoto FROM'GC:/ /「+ objADsPath +」'其中sAMAccountname ='「+ strUsername +」'「 個設置RS = Com.Execute Response.Expires = 0 ntin 將Response.Buffer = TRUE Response.Clear – Richard 2012-07-10 09:22:52

+0

Response.ContentType = 「圖像/ JPEG」 「####假設你的圖像是JPEG文件 如果不是RS。 EOF然後 Response.BinaryWrite RS( 「thumbnailPhoto」) 其他 的Response.Write&strUserName中和 「圖像」, 「未找到」 如果 結束 rs.Close con.Close 集RS =無 設定連接=無 %> – Richard 2012-07-10 09:23:06

0

你可以做到這一點使用html img標籤。例如:

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

在ASP代碼塊,你必須聲明爲:

<% 
    Response.Write "<img src=""" & myPhotoUrl & """>" 
%> 
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 
%>