Home All Groups Group Topic Archive Search About

Active Directory and ASP.NET 2.0

Author
21 Jun 2006 6:30 PM
NancyA
Hi -
I am successfully able to retrieve tokenGroups data for a given
sAmAccountName from a .NET 2.0 web page.  However, I'm still in test mode on
my own machine.  What will I need to do to access AD from the web page when
it goes out on a corporate IIS server?  Do I need to use a specific account
when creating the DirectoryEntry object?  This is for an intranet website
using Windows authentication so I'll know that any users are members of AD.

Thanks

Author
21 Jun 2006 7:27 PM
Joe Kaplan (MVP - ADSI)
It is vastly easier in ASP.NET 2.0 to get the user's group membership
directly from the WindowsIdentity object you get as a result of using
Windows authentication.

Just cast Context.User.Identity to a WindowsIdentity and read the Groups
property!  You can easily translate all of those into friendly names using
the IdentityReferenceCollection.Translate method.  You can also use the
WindowsPrincipal.IsInRole method to get a true/false answer as to whether a
user is in any particular group.

Another option if you are using membership is to use the windows token role
provider that comes with ASP.NET.

If you must do LDAP, then you have a variety of different options available
to you, depending on whether you want to use the authenticated user's
security context to access AD (a delegation architecture) or whether you
want to use a service account (a trusted subsystem architecture).  We go
into all of this stuff in great detail in our book in ch 8 if you are
interested.  I can also help out here if you want to pursue this further,
but hopefully you won't need to.

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
--
Show quoteHide quote
"NancyA" <anonym***@discussions.microsoft.com> wrote in message
news:D051F753-FF24-4278-B773-9B4C023796E6@microsoft.com...
> Hi -
> I am successfully able to retrieve tokenGroups data for a given
> sAmAccountName from a .NET 2.0 web page.  However, I'm still in test mode
> on
> my own machine.  What will I need to do to access AD from the web page
> when
> it goes out on a corporate IIS server?  Do I need to use a specific
> account
> when creating the DirectoryEntry object?  This is for an intranet website
> using Windows authentication so I'll know that any users are members of
> AD.
>
> Thanks
Author
22 Jun 2006 12:47 PM
NancyA
Gee, that was really easy!  Thanks for the very clear response.  I am now
using WindowsIdentity and WindowsPrincipal.IsInRole and it works beautifully
without needing to go to LDAP!

Show quoteHide quote
"NancyA" wrote:

> Hi -
> I am successfully able to retrieve tokenGroups data for a given
> sAmAccountName from a .NET 2.0 web page.  However, I'm still in test mode on
> my own machine.  What will I need to do to access AD from the web page when
> it goes out on a corporate IIS server?  Do I need to use a specific account
> when creating the DirectoryEntry object?  This is for an intranet website
> using Windows authentication so I'll know that any users are members of AD.
>
> Thanks
Author
22 Jun 2006 2:35 PM
Joe Kaplan (MVP - ADSI)
Glad that helped.  It only works when you can use Windows authentication,
but when you can, it works much better.  :)

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
--
Show quoteHide quote
"NancyA" <anonym***@discussions.microsoft.com> wrote in message
news:9A91D294-3964-4FD4-91C0-D5A406CC557C@microsoft.com...
> Gee, that was really easy!  Thanks for the very clear response.  I am now
> using WindowsIdentity and WindowsPrincipal.IsInRole and it works
> beautifully
> without needing to go to LDAP!
>
> "NancyA" wrote:
>
>> Hi -
>> I am successfully able to retrieve tokenGroups data for a given
>> sAmAccountName from a .NET 2.0 web page.  However, I'm still in test mode
>> on
>> my own machine.  What will I need to do to access AD from the web page
>> when
>> it goes out on a corporate IIS server?  Do I need to use a specific
>> account
>> when creating the DirectoryEntry object?  This is for an intranet website
>> using Windows authentication so I'll know that any users are members of
>> AD.
>>
>> Thanks