質問

拡張 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自身の例コードが機能することを期待していますが、そうではないので、当然、例に基づいて書き込もうとしているコードも機能していません。誰かがこの仕事をしましたか?

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

役に立ちましたか?

解決

探しているユーザーが実際にクラスに属していることを確認してください inetOrgPerson.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top