473,378 Members | 1,436 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,378 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 9042
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.