.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 9th, 2004, 02:37 PM
rhinton rhinton is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 19 rhinton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 41 sec
Reputation Power: 0
Question Trying to access the Active Directory through VB.NET Web Forms

I am very new to the VB.NET Web Forms, and I am creating this forms that will query the Active Directory. I need it
to return information like the user's email address. I know about the AD, but I just don't know how to access it through
VB.NET Web Forms. Could someone help please?

Reply With Quote
  #2  
Old November 15th, 2004, 04:35 PM
rhinton rhinton is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 19 rhinton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 41 sec
Reputation Power: 0
I really need some help on this, can someone please give me a life line.

Quote:
Originally Posted by rhinton
I am very new to the VB.NET Web Forms, and I am creating this forms that will query the Active Directory. I need it
to return information like the user's email address. I know about the AD, but I just don't know how to access it through
VB.NET Web Forms. Could someone help please?

Reply With Quote
  #3  
Old December 14th, 2004, 10:50 AM
rhinton rhinton is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 19 rhinton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 41 sec
Reputation Power: 0
I can't believe this. No one knows how this is done? Please this is killing me.

Reply With Quote
  #4  
Old December 21st, 2004, 10:20 AM
soscarlece soscarlece is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 1 soscarlece User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
get email from AD

[hear is an example for email from AD] hope this helps


PublicFunction GetEmailFromActDir(ByVal strUserName AsString) AsString
'################################################# ####################
'# gets user email from active dir based on the username, to connect #
'# to the active dir the userid as per connection has to be specified#
'# builds ldap function query, if there are more then one result for #
'# the search - exits the function, if only one then get the address #
'# from the properties collection #
'################################################# ####################
Dim strEmailAddress AsString
Try
Dim strPath AsString = LDAP://????.com/DC=????,DC=com
Dim strUserIds AsString = "????\userid, password" '#################!!!!!!!!!####
Dim objDirEntry AsNew System.DirectoryServices.DirectoryEntry(strPath, "????\userid", "password", DirectoryServices.AuthenticationTypes.Secure)
Dim objDirSearcher AsNew System.DirectoryServices.DirectorySearcher(objDirE ntry)

Dim objCollSearchResult As System.DirectoryServices.SearchResultCollection

Dim objlSearchResult As System.DirectoryServices.SearchResult

Dim objCollResultProperty As System.DirectoryServices.ResultPropertyCollection

Dim objCollResultPropertyValue As System.DirectoryServices.ResultPropertyValueCollec tion

objDirSearcher.Filter = ("(&(objectClass=user)(samaccountname=" & strUserName & "))")

objCollSearchResult = objDirSearcher.FindAll()

SelectCase objCollSearchResult.Count

Case 0

strEmailAddress = ""

CaseIs > 1

ExitFunction

CaseIs = 1



objlSearchResult = objCollSearchResult.Item(0)

objCollResultProperty = objlSearchResult.Properties

objCollResultPropertyValue = objCollResultProperty.Item("mail")

strEmailAddress = objCollResultPropertyValue.Item(0)

EndSelect

'################################################# #########

'# forced disposing #

'################################################# #########

objDirEntry.Dispose()

objDirSearcher.Dispose()

objCollSearchResult.Dispose()

objlSearchResult =
Nothing

objCollResultProperty = Nothing

objCollResultPropertyValue = Nothing

Catch ex As System.Exception

Dim strMess AsString

strMess = ex.Message

strEmailAddress = ""

EndTry

Return strEmailAddress

EndFunction


Reply With Quote
  #5  
Old December 21st, 2004, 12:10 PM
rhinton rhinton is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 19 rhinton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 41 sec
Reputation Power: 0
now where would I place this code so I could use the strEmailAddress on the other forms?

Reply With Quote
  #6  
Old December 21st, 2004, 02:40 PM
rhinton rhinton is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 19 rhinton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 41 sec
Reputation Power: 0
Also, do I have to input the userid and password? What I want to happen is the user go the url of the web form and when they get to the page that request the email address I want the form to return their email address from active directory. I don't want the userid and password exposed to anyone. Is it possible?

Reply With Quote
  #7  
Old January 4th, 2005, 07:30 AM
Programmaticus Programmaticus is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Location: South Africa
Posts: 1 Programmaticus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile Complete solution to your AD and email problem.

Yes, it is imperitive that you supply the username for authentication purposes required by LDAP (according to my knowledge), otherwise, how do you indicate to LDAP which users email addresses you want to extract? So it makes only sense.
To be able to use the returned emailaddress string variable in your other forms you must declare a public variable to save the returned value in, which you can subsequently use throughout your Windows Forms Application. Here is an example:

Add a new Module to your project and declare a Public variable inside your new module:
Module Module1

Public EmailAddress As String 'This variable is now accessible throughout your whole application.

End
Module



PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Assign the email address returned by the function to the public variable - you can now use this variable throughout
'your application

EmailAddress = GetEmailFromActDir("JohnD")
EndSub



Public Function GetEmailFromActDir(ByVal strUserName AsString) AsString
'################################################# ####################
'# gets user email from active dir based on the username, to connect #
'# to the active dir the userid as per connection has to be specified#
'# builds ldap function query, if there are more then one result for #
'# the search - exits the function, if only one then get the address #
'# from the properties collection #
'################################################# ####################
Dim strEmailAddress AsString
Try
Dim strPath AsString = LDAP://????.com/DC=????,DC=com (ldap:///????.com/DC=????,DC=com)
Dim strUserIds AsString = "????\userid, password" '#################!!!!!!!!!####
Dim objDirEntry AsNew System.DirectoryServices.DirectoryEntry(strPath, "????\userid", "password", DirectoryServices.AuthenticationTypes.Secure)
Dim objDirSearcher AsNew System.DirectoryServices.DirectorySearcher(objDirE ntry)

Dim objCollSearchResult As System.DirectoryServices.SearchResultCollection

Dim objlSearchResult As System.DirectoryServices.SearchResult

Dim objCollResultProperty As System.DirectoryServices.ResultPropertyCollection

Dim objCollResultPropertyValue As System.DirectoryServices.ResultPropertyValueCollec tion

objDirSearcher.Filter = ("(&(objectClass=user)(samaccountname=" & strUserName & "))")

objCollSearchResult = objDirSearcher.FindAll()

SelectCase objCollSearchResult.Count

Case 0

strEmailAddress = ""

CaseIs > 1

ExitFunction

CaseIs = 1



objlSearchResult = objCollSearchResult.Item(0)

objCollResultProperty = objlSearchResult.Properties

objCollResultPropertyValue = objCollResultProperty.Item("mail")

strEmailAddress = objCollResultPropertyValue.Item(0)

EndSelect

'################################################# #########

'# forced disposing #

'################################################# #########

objDirEntry.Dispose()

objDirSearcher.Dispose()

objCollSearchResult.Dispose()

objlSearchResult = Nothing

objCollResultProperty = Nothing

objCollResultPropertyValue = Nothing

Catch ex As System.Exception

Dim strMess AsString

strMess = ex.Message

strEmailAddress = ""

EndTry

Return strEmailAddress

End Function

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgramming.NET Development > Trying to access the Active Directory through VB.NET Web Forms


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap