ユーザーが C# のグループのメンバーであるかどうかを確認したい。アプリケーションは Windows Mobile 6.1 で実行されており、ldap 関数を使用する必要があります[DllImport]
。
誰かがこれのサンプルを持っていますか? LDAP サーバーに接続し、ユーザー/パスワードが機能することを確認します。
ユーザーが C# のグループのメンバーであるかどうかを確認したい。アプリケーションは Windows Mobile 6.1 で実行されており、ldap 関数を使用する必要があります[DllImport]
。
誰かがこれのサンプルを持っていますか? LDAP サーバーに接続し、ユーザー/パスワードが機能することを確認します。
フレームワークにすでにあるものを使用しないのはなぜですか。
これを見てください:WindowsPrincipal.IsInRoleメソッド(文字列)
WindowsIdentity identity = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(identity);
principal.IsInRole("role name");
また
C#/ VB.NetおよびSystem.DirectoryServicesを使用する場合、このスニペットでうまくいくはずです。
DirectoryEntry rootEntry = new DirectoryEntry("LDAP://dc=yourcompany,dc=com");
DirectorySearcher srch = new DirectorySearcher(rootEntry);
srch.SearchScope = SearchScope.Subtree;
srch.Filter = "(&(objectClass=user)(sAMAccountName=yourusername)(memberof=CN=yourgroup,OU=yourOU,DC=yourcompany,DC=com))";
SearchResultCollection res = srch.FindAll();
if(res == null || res.Count <= 0)
Console.WriteLine("This user is NOT a member of this group");
else
Console.WriteLine("This user is INDEED a member of this group");
注意:これは、即時のグループメンバーシップのみをテストし、ドメインの「プライマリグループ」(通常は「cn = Users」)のメンバーシップはテストしません。ネストされたメンバーシップは処理されません。たとえば、ユーザーAはグループBのメンバーであるグループAのメンバーです。ユーザーAが実際にはグループBのメンバーであるという事実は、ここには反映されません。