2011-12-22 10 views
1

DBテーブルの情報を使用して広告を更新する小さなアプリケーションを作成していますが、ベストプラクティスの例を見つけるのに問題があります。フィルタobjectClass=userDirectorySearcherを作成した、私がハンドルを取得するresult.getDirectoryEntryを使用する必要がある場合は、指定のCN DirectoryServiceでユーザーを更新する

  • を検索

    • 私の知る限り理解し、私がする必要があります実際のオブジェクトに、自分のDBから、その後で私のentryobjectから

    • アップデートすべての値は

    があることです変更をコミットそれは完全に失われています。ヒントや例があれば歓迎します。

  • 答えて

    1

    .NET 3.5以降では、System.DirectoryServices.AccountManagement(S.DS.AM)名前空間をチェックアウトする必要があります。ここではそれについてのすべてを読む:

    基本的に、あなたはドメインコンテキストを定義し、簡単にADのユーザーおよび/またはグループを見つけることができます:

    // set up domain context 
    PrincipalContext ctx = new PrincipalContext(ContextType.Domain); 
    
    // find a user 
    UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "SomeUserName"); 
    
    if(user != null) 
    { 
        // update the properties you need to 
        user.DisplayName = "Joe Blow"; 
        user.Description = "Some description"; 
    
        // save back your changes 
        user.Save(); 
    } 
    

    新しいS.DS.AMにより、ADのユーザーやグループで簡単に遊ぶことができます。

    あなたは、ユーザーの全体の束を検索する必要がある場合は、あなたがあなたの検索を行うことPrincipalSearcherと「例による問合せ」プリンシパルを使用することができます。

    // create your domain context 
    PrincipalContext ctx = new PrincipalContext(ContextType.Domain); 
    
    // define a "query-by-example" principal - here, we search for a UserPrincipal 
    // and with the first name (GivenName) of "Bruce" 
    UserPrincipal qbeUser = new UserPrincipal(ctx); 
    qbeUser.GivenName = "Bruce"; 
    
    // create your principal searcher passing in the QBE principal  
    PrincipalSearcher srch = new PrincipalSearcher(qbeUser); 
    
    // find all matches 
    foreach(var found in srch.FindAll()) 
    { 
        // do whatever here - "found" is of type "Principal" - it could be user, group, computer.....   
        UserPrincipal user = found as UserPrincipal; 
    
        if(user != null) 
        { 
         // update the properties you need to 
         user.DisplayName = "Joe Blow"; 
         user.Description = "Some description"; 
    
         // save back your changes 
         user.Save(); 
        } 
    } 
    

    あなたは上の任意のプロパティを指定することができますUserPrincipalを入力し、PrincipalSearcherの場合は「例によるクエリ」として使用してください。

    +0

    お返事ありがとうございます。 AccountManagementについて聞いたことがありますが、誰かがアクセスできる属性に非常に制限されていると教えてくれましたか?私は拡張属性に多くのデータを保存していますが、私はまだS.DS.AMを使用できますか? – elwis

    +0

    @elwis:私がリンクした記事を読んでください! 'UserPrincipal'クラスをあなたのニーズに合わせて拡張することができます。はい、あなたはまだあなたの仕事にS.DS.AMを使用することができます!他のすべてが失敗した場合、 '.GetUnderlyingObject()'を呼び出して、 'UserPrincipal'に属する' DirectoryEntry'を手にして、そこで拡張属性の更新を処理できます。 –

    +0

    コメントするHav。私はその解決策と一緒に行くことができませんでしたが、私はまだあなたの記事を読んで、それは本当に素晴らしい解決策であるようです。うまくいけば次回、リンクありがとう – elwis

    関連する問題