RE: DirectoryEntry issue

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



CJ,

It sounds like you are having permission errors. Where is the assembly
loaded? If it is in the bin directory what is the trust level set at in the
web.config. If the assembly is in the bin try it in the GAC and see if that
works for you.

Mike

"cj_mcsd" wrote:

> I wrote this code to check membership in a aspx page of an AD group:
>
> ----code starts----------
> DirectoryEntry deUser = new
> DirectoryEntry(@"LDAP://DomainControlerServName/CN=UserFQN,CN=Users,DC=domain,DC=com","adminID","adminPswd",AuthenticationTypes.ReadonlyServer);
> foreach(string name in deUser.Properties.PropertyNames)
> {
> if (name == "memberOf")
> {
> Response.Write(name);
> Response.Write("<br>");
> foreach (object o in deUser.Properties[name])
> {
> Response.Write(o.ToString());
> Response.Write("<br>");
> }
> }
> }
> ---code ends------------
> Works great, but then I moved it over to SPS2003 webpart
>
> --code starts here------------------
>
> DirectoryEntry deUser = new
> DirectoryEntry(@"LDAP://DomainControlerServName/CN=UserFQN,CN=Users,DC=domain,DC=com","adminID","adminPswd",AuthenticationTypes.ReadonlyServer);
> foreach(string name in deUser.Properties.PropertyNames)
> {
> if (name == "memberOf")
> {
> output.Write(name);
> foreach (object o in deUser.Properties[name])
> {
> output.Write(o.ToString());
> }
> }
> }
> --code ends here-------------------
> The part when added to a page takes me to the webpart error page so I
> removed it and then added it back with nothing but
>
> DirectoryEntry deUser = new
> DirectoryEntry(@"LDAP://DomainControlerServName/CN=UserFQN,CN=Users,DC=domain,DC=com","adminID","adminPswd",AuthenticationTypes.ReadonlyServer);
>
> that didn't work [got error webpart page]
> then I tried ....
>
> DirectoryEntry deUser = new DirectoryEntry();
>
> same webpart error. The I took that out of the webpart and it lets me add
> it ok and everything so the control is registered fine. I also have the
> correct "using" statement adding DirectoryServices:
>
> using System.DirectoryServices;
>
>
> Seems like maybe there is some configuration step I am missing to allow me
> to use the DirectoryServices Library.
>
> How about some good advice on what I am doing wrong.
>
>
>
>
>
>
>
> --
> --cj MCSD
.