469,352 Members | 1,889 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

Retrieving users email address

CJM
I'm trying to retrieve the users email address via ADSI in ASP.

So far, I have the following code:

Set oUser = GetObject("WinNT://domain/" & Request.Form("UID") & ",user")
Response.Write oUser.EmailAddress

But I get the following message:

"The directory property cannot be found in the cache. "

Any ideas where I am going wrong?

Thanks
Jul 22 '05 #1
8 8804
On Fri, 19 Nov 2004 16:33:30 -0000, "CJM"
<cj*******@newsgroups.nospam> wrote:
I'm trying to retrieve the users email address via ADSI in ASP.

So far, I have the following code:

Set oUser = GetObject("WinNT://domain/" & Request.Form("UID") & ",user")
Response.Write oUser.EmailAddress

But I get the following message:

"The directory property cannot be found in the cache. "

Any ideas where I am going wrong?


First guess is you're looking for a directory property that isn't in
the cache... :)

You're going to need to get specific and tell us versions of OS,
Active Directory or not, etc. Also, if the email address isn't in
your directory, you're still not going to get anything.

Jeff
Jul 22 '05 #2
CJM wrote:
I'm trying to retrieve the users email address via ADSI in ASP.

So far, I have the following code:

Set oUser = GetObject("WinNT://domain/" & Request.Form("UID") & ",user")
Response.Write oUser.EmailAddress

But I get the following message:

"The directory property cannot be found in the cache. "

Any ideas where I am going wrong?


Hi,

I find that EmailAddress is not supported by the WinNT provider. You need to
uses the LDAP provider.

EmailAddress is actually a property method that returns the value of the
mail attribute (which also is not supported by WinNT).

--
Richard
Microsoft MVP Scripting and ADSI
HilltopLab web site - http://www.rlmueller.net
--
Jul 22 '05 #3
CJM

"Jeff Cochran" <je*********@zina.com> wrote in message
news:41*****************@msnews.microsoft.com...
On Fri, 19 Nov 2004 16:33:30 -0000, "CJM"
<cj*******@newsgroups.nospam> wrote:
I'm trying to retrieve the users email address via ADSI in ASP.

So far, I have the following code:

Set oUser = GetObject("WinNT://domain/" & Request.Form("UID") & ",user")
Response.Write oUser.EmailAddress

But I get the following message:

"The directory property cannot be found in the cache. "

Any ideas where I am going wrong?


First guess is you're looking for a directory property that isn't in
the cache... :)

You're going to need to get specific and tell us versions of OS,
Active Directory or not, etc. Also, if the email address isn't in
your directory, you're still not going to get anything.

Jeff


Jeff,

My development server is XPSP2 and we are using Active Directory 2003
(Native mode).

All the email address are populated.

Thanks

Chris
Jul 22 '05 #4
CJM

"Richard Mueller [MVP]" <rl**************@ameritech.NOSPAM.net> wrote in
message news:%2****************@TK2MSFTNGP12.phx.gbl...

Hi,

I find that EmailAddress is not supported by the WinNT provider. You need
to
uses the LDAP provider.

EmailAddress is actually a property method that returns the value of the
mail attribute (which also is not supported by WinNT).

--
Richard


Thanks Richard, but can you point me in the right direction for the LDAP
code. I gather its more involved than just swapping 'WinNT' for 'LDAP' - a
different string entirely?

Cheers

Chris
Jul 22 '05 #5
On Tue, 23 Nov 2004 12:39:53 -0000, "CJM"
<cj*******@newsgroups.nospam> wrote:

"Jeff Cochran" <je*********@zina.com> wrote in message
news:41*****************@msnews.microsoft.com.. .
On Fri, 19 Nov 2004 16:33:30 -0000, "CJM"
<cj*******@newsgroups.nospam> wrote:
I'm trying to retrieve the users email address via ADSI in ASP.

So far, I have the following code:

Set oUser = GetObject("WinNT://domain/" & Request.Form("UID") & ",user")
Response.Write oUser.EmailAddress

But I get the following message:

"The directory property cannot be found in the cache. "

Any ideas where I am going wrong?


First guess is you're looking for a directory property that isn't in
the cache... :)

You're going to need to get specific and tell us versions of OS,
Active Directory or not, etc. Also, if the email address isn't in
your directory, you're still not going to get anything.

Jeff


Jeff,

My development server is XPSP2 and we are using Active Directory 2003
(Native mode).

All the email address are populated.


In AD? If so, you'll want to use LDAP to retrieve them instead of
WMI.

Jeff
Jul 22 '05 #6
On Tue, 23 Nov 2004 12:42:03 -0000, "CJM"
<cj*******@newsgroups.nospam> wrote:

"Richard Mueller [MVP]" <rl**************@ameritech.NOSPAM.net> wrote in
message news:%2****************@TK2MSFTNGP12.phx.gbl...

Hi,

I find that EmailAddress is not supported by the WinNT provider. You need
to
uses the LDAP provider.

EmailAddress is actually a property method that returns the value of the
mail attribute (which also is not supported by WinNT).

--
Richard


Thanks Richard, but can you point me in the right direction for the LDAP
code. I gather its more involved than just swapping 'WinNT' for 'LDAP' - a
different string entirely?


Lots of sampels availble, try:

http://www.4guysfromrolla.com/webtech/041800-1.shtml

Jeff
Jul 22 '05 #7
CJM
Here's the solution I ended up with:

<%@language="vbscript" %>
<%
Option Explicit

Dim objRootDSE, strDNSDomain, objConnection, strQuery
Dim objRecordSet, strName, strDN
Dim strBase, strFilter, strAttributes

' Determine DNS domain name from RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")

' Use ADO to search Active Directory.
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Properties("User ID") = "domain\username"
objConnection.Properties("Password") = "password"
objConnection.Open "Active Directory Provider"

' Search for all user objects. Sort recordset by DisplayName.
strBase = "<LDAP://" & strDNSDomain & ">"
strFilter = "(&(objectCategory=person)(objectClass=user)(sAMAc countName=" &
Session("UID") & "))"
strAttributes = "mail"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"

Set objRecordSet = objConnection.Execute(strQuery)

If objRecordSet.EOF Then
response.Write "bolox"
End If

' Loop through results
Do Until objRecordSet.EOF
response.Write "Email Address: " & objRecordSet.Fields("mail")
objRecordSet.MoveNext
Loop

' Clean up.
objConnection.Close
Set objRootDSE = Nothing
Set objConnection = Nothing
Set objRecordSet = Nothing

%>
I was told that the mail property is not always reliable, ie may not be
populated, and that the proxyaddresses field would be better, but that
returns a multi-value responsew which I can't seem to handle. Besides, mail
seems to work OK for me...

Thanks

Chris

Jul 22 '05 #8
Hi,

Some comments.

1. If you know "mail" is populated, use it.
2. You don't need to specify a userID and password unless you are running
the code with an account that does not have permisssion to read the
attributes.
3. To read a multi-valued attribute, you can loop through the collection
with a "For Each" loop. However, you must account for the possibility that
the attribute will have no values. For example:

' Retrieve a multi-valued attribute .
strAttributes = "proxyAddresses"

Do Until adoRecordset.EOF
colMail = adoRecordset.Fields("proxyAddresses")
If IsEmpty(colMail) Then
' The attribute is empty (has no values).
Response.Write "No Email address"
Else
' The attribute has one or more values - enumerate.
For Each strMail In colMail
Response.Write "Email Address: " & strMail
Next
End If
Loop

--
Richard
Microsoft MVP Scripting and ADSI
HilltopLab web site - http://www.rlmueller.net
--

"CJM" <cj*******@newsgroups.nospam> wrote in message
news:eN**************@TK2MSFTNGP15.phx.gbl...
Here's the solution I ended up with:

<%@language="vbscript" %>
<%
Option Explicit

Dim objRootDSE, strDNSDomain, objConnection, strQuery
Dim objRecordSet, strName, strDN
Dim strBase, strFilter, strAttributes

' Determine DNS domain name from RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")

' Use ADO to search Active Directory.
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Properties("User ID") = "domain\username"
objConnection.Properties("Password") = "password"
objConnection.Open "Active Directory Provider"

' Search for all user objects. Sort recordset by DisplayName.
strBase = "<LDAP://" & strDNSDomain & ">"
strFilter = "(&(objectCategory=person)(objectClass=user)(sAMAc countName=" & Session("UID") & "))"
strAttributes = "mail"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"

Set objRecordSet = objConnection.Execute(strQuery)

If objRecordSet.EOF Then
response.Write "bolox"
End If

' Loop through results
Do Until objRecordSet.EOF
response.Write "Email Address: " & objRecordSet.Fields("mail")
objRecordSet.MoveNext
Loop

' Clean up.
objConnection.Close
Set objRootDSE = Nothing
Set objConnection = Nothing
Set objRecordSet = Nothing

%>
I was told that the mail property is not always reliable, ie may not be
populated, and that the proxyaddresses field would be better, but that
returns a multi-value responsew which I can't seem to handle. Besides, mail seems to work OK for me...

Thanks

Chris

Jul 22 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by zsh-users-help | last post: by
reply views Thread by tcm-users-request | last post: by
4 posts views Thread by codewarr2000 | last post: by
9 posts views Thread by Larry | last post: by
2 posts views Thread by 4Ankit | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.