Re: Query AD Impersonating Userīs Credentials

From: George Luiz Bittencourt (george@integral.inf.br)
Date: 10/16/02


From: "George Luiz Bittencourt" <george@integral.inf.br>
Date: Wed, 16 Oct 2002 13:58:57 -0700


The problem is that itīs not working. The query returns
nothing. Any idea?

Thanks,

George Luiz Bittencourt

>-----Original Message-----
>Ok, but what is the problem you encounter?
>
>Willy.
>
>"George Luiz Bittencourt" <george@integral.inf.br> wrote
in message news:30e301c2748d$ff497490
$37ef2ecf@TKMSFTNGXA13...
>Hi,
>
>I have an Web Application in ASP.NET that need to
>query the
>Active Directory using the credentials of the user
>accessing the page.
>
>I have set the following options on my Web.Config file:
>
><authentication mode="Windows" />
><identity impersonate="true"/>
>
>I have set the IIS Virtual Directory options to:
>Integrated Windows Authentication.
>
>The problem is: i would like to query AD with the userīs
>credentials used to access the page.
>I have tried several methods to do it. The last one uses
>WindowsImpersonationContext as you can see
>below.
>
>public static SearchResultCollection queryAD(string
>lsquery, System.Security.Principal.IPrincipal usr)
>{
>System.Security.Principal.WindowsImpersonationConte
>xt impersonationContext;
>impersonationContext =
>((System.Security.Principal.WindowsIdentity)
>usr.Identity).Impersonate();
>DirectoryEntry root = new DirectoryEntry("GC:");
>
>IEnumerator ie = root.Children.GetEnumerator();
>ie.MoveNext();
>root = (DirectoryEntry)ie.Current;
>
>DirectorySearcher searcher=new DirectorySearcher
>(root);
>
>searcher.Filter = lsquery;
>searcher.PropertiesToLoad.Add("member");
>searcher.PropertiesToLoad.Add("memberOf");
>return searcher.FindAll();
>
>}
>
>
>Thanks!
>
>George Luiz Bittencourt
>
>
>.
>


Quantcast