سؤال

تمتد 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() يعود فارغ ، على هذا النحو:

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

في الواقع ، من الداخل InetOrgPerson.FindByIdentity(), ، الدعوة إلى FindByIdentityWithType() يعود فارغ ، على هذا النحو:

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