473,242 Members | 2,323 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,242 software developers and data experts.

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 9035
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: zsh-users-help | last post by:
Hi! This is the ezmlm program. I'm managing the zsh-users@sunsite.dk mailing list. To confirm that you would like python-list@python.org removed from the zsh-users mailing list, please send...
0
by: tcm-users-request | last post by:
This pre-recorded message is being sent in response to your recent email to tcm-users-request@listserv.cs.utwente.nl. All routine administrative requests (including subscriptions and...
15
by: Viviana Vc | last post by:
How can I programatically do the equivalent of the following: cacls "C:\Program Files\test" /T /G Everyone:f ? Thanks, Viv
4
by: codewarr2000 | last post by:
Having problem with retrieving a class instance item from a Vector. This is the result of the code below. Also a weird note: If I dont declare as: TYPE_VECTOR_BANKED_MEMORY_DATA...
0
by: Alistair | last post by:
Hi all, I am creating a database based site that keeps track of books, who has read them and the comments they have. After a little help in M.P.I.asp.DB I managed to create a database (access...
9
by: Larry | last post by:
OK, I've been searching around the net for numerous hours and seem to just be getting more confused about handling special characters. In my host's configuration MagicQuotes is ON. (I understand...
2
by: 4Ankit | last post by:
hello all, i am having some difficulty retrieving information from my form. I want to add content in my table but the content i want to add to the table is what the user inputs in my form. ...
4
by: smartin | last post by:
Hi, I'm having problem retrieving data from an SQL stored procedure. I tried debugging but it wont give a the reason for the error. it just throws an exception after executing cmd.ExecuteNonQuery...
34
by: vpriya6 | last post by:
Hi guys, I am new to Ajax, xml and javascript. I want to know how can I retrieve data from xml and display in the html page? please help me out. suppose my xml file is customer.xml the code...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.