Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Security / August 2006

Tip: Looking for answers? Try searching our database.

Active Directory Access from a Web App

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jon Schneider - 28 Aug 2006 15:03 GMT
I am trying to access employee information from Active Directory from my ASP
.Net web application. I have tried several different methods and each fail.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load

Dim user As MembershipUser = Membership.GetUser(User.Identity.Name)
       
userName.Text = user.UserName
emailAddress.Text = user.Email

End Sub

This method returns this error:

Object reference not set to an instance of an object.
at _Default.Page_Load(Object sender, EventArgs e)

The other method I was investigating is using WindowsIdentity. I can access
the SID but I do not know how to utilize the DirectoryEntry, or what to
include to obtain the users email address.

Any help would be greatly appreciated.

Signature

Software Development Manager
GRG Inc.
Maitland, Florida 32751
www.grgce.com

Joe Kaplan - 28 Aug 2006 15:16 GMT
If you want to use LDAP/System.DirectoryServices directly, I wrote a whole
book about that stuff that might be useful to you (see link in the
signature).  There's a free chapter and code samples available for download
if you want to try before you buy.  :)

Essentially, if you have the SID of the user, you can create a binding
string for the DirectoryEntry like this:

LDAP://<SID=S-1-5-20-xxxxx>

Where the SID value shown there is the value you get from calling ToString
on the SecurityIdentifier object.  Once you have that, then getting the
user's email is easy:

string mail = (string) entry.Properties["mail"].Value;

The main trick may be figuring out how to set up the security context
properly in ASP.NET to access the directory.  This is covered in detail in
ch 8, and I've posted on numerous approaches to this problem in these
newsgroups over the years the Google will find for you.

Best of luck,

Joe K.

Signature

Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
--

>I am trying to access employee information from Active Directory from my
>ASP
[quoted text clipped - 23 lines]
>
> Any help would be greatly appreciated.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.