0

GroupID と関連する UserName を格納する UserGroup テーブルがあります。現在、ユーザーは Active Directory 内に存在するため、Users テーブルはありません。ただし、ユーザーを UserGroup テーブルに割り当てる前に、ユーザーが Active Directory 内で既に定義されているかどうかを確認する必要があります。したがって、UserGroup Model オブジェクト内に検証オブジェクトを記述することは良いアプローチであることがわかったので、USerGroup Partial クラス内に次のように記述しました:-

List<DomainContext> results = new List<DomainContext>();
using (var context = new PrincipalContext(ContextType.Domain, "WIN-SPDEV"))
using (var searcher = new PrincipalSearcher(new UserPrincipal(context)))
{
   var searchResults = searcher.FindAll();
   foreach (Principal p in searchResults)
   {
     //not sure what to write here !!!
}}
yield return new ValidationResult("UserName does not exsists.");}

しかし、一意性チェックを実装する方法がわかりません!!!

4

2 に答える 2

1

このコードを試してください:

var searchResults = searcher.FindAll();
foreach (Principal p in searchResults)
{
  if(p.SamAccountName == User.Identity.Name)
  {
      //your in!
  }
}
于 2013-07-16T13:31:10.317 に答える
1

試す:

using (var context = new PrincipalContext(ContextType.Domain, "WIN-SPDEV"))
{
    UserPrincipal user = UserPrincipal.FindByIdentity(context, searchedUserName);
    if (user != null)
    {
        //user found
    }
}
于 2013-07-16T13:33:48.250 に答える