8

UserPrincipal को अपने अंतर्निहित गुणों का लाभ उठाने में विफल रहता है ... जब हम FindByIdentity() विधि को अधिभारित करते हैं तो किसी समस्या में चल रहा है।उपयोगकर्ता प्रिंसिपल का विस्तार; FindByIdentity()

माइक्रोसॉफ्ट के उदाहरण से 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 ऑब्जेक्ट पर नहीं डाला जा सकता है, मुझे वापस लौटने की आवश्यकता है।

क्या देता है? मैं माइक्रोसॉफ्ट के अपने उदाहरण कोड को काम करने की उम्मीद करता हूं, लेकिन ऐसा नहीं है, इसलिए स्वाभाविक रूप से कोड जो मैं उदाहरण के आधार पर लिखने की कोशिश कर रहा हूं वह काम नहीं कर रहा है। क्या किसी ने यह काम किया है?

अग्रिम धन्यवाद! जेम्स

उत्तर

12

सुनिश्चित करें कि उपयोगकर्ता आप वास्तव में खोजे जा रहे वर्ग inetOrgPerson के अंतर्गत आता है सुनिश्चित करें।

+2

हाँ, यह समस्या थी। मुझे एहसास नहीं हुआ कि 'DirectoryObjectClass' विशेषता मैंने सेट को कक्षा में एडी में कक्षा में बांध दिया है। तो अब मैं समझता हूं कि जब मैं इस वर्ग की 'FindByIdentity' के माध्यम से एक खोज करता हूं, तो मैं अपनी खोज को कक्षा' inetOrgPerson 'के ऑब्जेक्ट में सीमित कर रहा हूं, जिसमें से हमारे एडी में कोई भी नहीं है। मेरे मामले में, मैं 'DirectoryObjectClass' को 'उपयोगकर्ता' पर सेट करना चाहता हूं। यह वास्तव में बहुत अच्छा है। धन्यवाद! –

+0

कमाल, मेरे लिए भी एक मुद्दा तय किया – nokturnal

संबंधित मुद्दे

 संबंधित मुद्दे