Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Security > Active Directory Access from a Web App

Reply
Thread Tools

Active Directory Access from a Web App

 
 
Jon Schneider
Guest
Posts: n/a
 
      08-28-2006
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.

--
Software Development Manager
GRG Inc.
Maitland, Florida 32751
www.grgce.com
 
Reply With Quote
 
 
 
 
Joe Kaplan
Guest
Posts: n/a
 
      08-28-2006
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.

--
Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
--
"Jon Schneider" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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.
>
> --
> Software Development Manager
> GRG Inc.
> Maitland, Florida 32751
> www.grgce.com



 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
web app authentication to active directory Nick Brown Ruby 3 03-18-2010 08:18 PM
How to access Active Directory from web application? Hvid Hat ASP .Net 1 03-17-2009 08:26 AM
problem accesing Active Directory from an ASP.NET App when user has been authenticated via AD certificate mapping Sergio Lera via .NET 247 ASP .Net Security 1 04-06-2005 05:53 PM
Active Directory Search fails ("The directory service is unavailab ejcosta ASP .Net Security 2 10-08-2004 09:57 AM
question regarding overriding of web.config in the root directory..in a web app in a virtual directory dotnetprogram ASP .Net 1 12-27-2003 06:02 AM



Advertisments