Re: DirectoryServices: what's wrong with my COM interop?
From: Marc Scheuner [MVP ADSI] (m.scheuner_at_inova.SPAMBEGONE.ch)
Date: 03/22/04
- Next message: Cor: "Re: Creating a map with Hotspot Images"
- Previous message: Marc Scheuner [MVP ADSI]: "Re: IADsPropertyList and IADsPropertyEntry in .NET"
- In reply to: Natalia DeBow: "DirectoryServices: what's wrong with my COM interop?"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 22 Mar 2004 08:10:28 +0100
Hi Natalia,
>In my app, I need to check if the current user is a member of the
>Administrators group in order to allow/deny some action.
Is there any particular reason why you start using the nice S.DS
namespace, and then go back to the "old-style", messy IADs
interfaces??
Unless you have some very specific reason for it, I'd stick to using
S.DS all the way - it's MUCH nicer and easier to use!
Also, another point: why do you use the WinNT provider?? That provider
is old, deprecated, and really only provided for backwards
compatibility with NT4 systems. if ever possible, AVOID it at all
costs - use LDAP instead.
To check if a given user is member of the "Administrators" group,
you'll need to
a) know your user's LDAP path
b) know your "Administrators" LDAP path
Given those two, you can easily detect this condition in S.DS
// set up the strings - user needs to be the fully qualified LDAP path
// including the LDAP:// provider prefix, while the "Administrators"
// string needs to be just the DN (distinguishedName) of the group
string sUser = "LDAP://cn=Natalia,ou=SomeOU,dc=yourcompany,dc=com";
string sAdmGrp = "cn=Administrators,cn=Builtin,dc=yourcompany,dc=com";
// bind to the user
DirectoryEntry deUser = new DirectoryEntry(sUser);
// enumerate it's "member" strings to see if it's
/ member of "Administrators"
bool bIsMemberOfAdmin = false;
foreach(object oGrp in deUser.Properties["member"])
{
if(oGrp.ToString() == sAdmGrp)
{
bIsMemberOfAdmin = true;
break;
}
}
if(bIsMemberOfAdmin)
// ..... do one thing
else
// do something else
Marc
================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
- Next message: Cor: "Re: Creating a map with Hotspot Images"
- Previous message: Marc Scheuner [MVP ADSI]: "Re: IADsPropertyList and IADsPropertyEntry in .NET"
- In reply to: Natalia DeBow: "DirectoryServices: what's wrong with my COM interop?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|