8

UserPrincipal組み込みのプロパティを利用するために拡張しています...FindByIdentity()メソッドをオーバーロードすると問題が発生します。

Microsoft の例( http://msdn.microsoft.com/en-us/library/bb384372%28VS.90%29.aspx ) から:

[DirectoryRdnPrefix("CN")]
[DirectoryObjectClass("inetOrgPerson")]
public class InetOrgPerson : UserPrincipal {

   // Implement the overloaded search method FindByIdentity
   public static new InetOrgPerson FindByIdentity(PrincipalContext context, 
                                                  string identityValue) {
       return (InetOrgPerson)FindByIdentityWithType(context,
                                                    typeof(InetOrgPerson),
                                                    identityValue);
   }

   // Implement the overloaded search method FindByIdentity
   public static new InetOrgPerson FindByIdentity(PrincipalContext context, 
                                                  IdentityType identityType, 
                                                  string identityValue) {
       return (InetOrgPerson)FindByIdentityWithType(context, 
                                                    typeof(InetOrgPerson), 
                                                    identityType,
                                                    identityValue);
   } 
}

MSDN の例から正確なコードを取得してアプリに貼り付けても、機能しません。への呼び出しは、次のInetOrgPerson.FindByIdentity()ように null を返します。

if (null == InetOrgPerson.FindByIdentity(principalContext, UserName)) {
     throw new Exception("bah");
}

実際、 内から をInetOrgPerson.FindByIdentity()呼び出すと、次のようにFindByIdentityWithType()null が返されます。

if (null == FindByIdentityWithType(context, typeof(InetOrgPerson), identityType, identityValue) {
    throw new Exception("bah");
}

ただし、呼び出し:

FindByIdentityWithType(context, typeof(UserPrincipal), identityType, identityValue)

必要なユーザー オブジェクトを提供します。InetOrgPersonただし、返す必要のあるオブジェクトにキャストできないため、使用できません。

何を与える?Microsoft 独自のサンプル コードが機能することを期待しますが、機能しないため、サンプルに基づいて記述しようとしているコードも機能しません。誰かがこれを機能させましたか?

前もって感謝します!ジェームズ

4

1 に答える 1

13

検索しているユーザーが実際に class に属していることを確認してくださいinetOrgPerson

于 2010-08-18T20:56:26.037 に答える