L'extension UserPrincipal; FindByIdentity () échoue
-
29-09-2019 - |
Question
L'extension de UserPrincipal
à tirer profit de ses propriétés intégrées ... en cours d'exécution dans un problème lorsque nous surcharger la méthode FindByIdentity()
.
A partir de l'exemple de Microsoft à l'adresse http: // msdn. microsoft.com/en-us/library/bb384372%28VS.90%29.aspx (parties exclues par souci de concision):
[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);
}
}
Si je prends le code exact de l'exemple MSDN et le coller dans mon application, il ne fonctionne pas. L'appel à des rendements de InetOrgPerson.FindByIdentity()
nulle, en tant que tel:
if (null == InetOrgPerson.FindByIdentity(principalContext, UserName)) {
throw new Exception("bah");
}
En fait, à partir de InetOrgPerson.FindByIdentity()
, l'appel retourne FindByIdentityWithType()
nulle, en tant que tel:
if (null == FindByIdentityWithType(context, typeof(InetOrgPerson), identityType, identityValue) {
throw new Exception("bah");
}
Cependant, l'appel:
FindByIdentityWithType(context, typeof(UserPrincipal), identityType, identityValue)
me donne l'objet utilisateur que je veux. Je dois revenir à moins que je ne peux pas l'utiliser, car il ne peut pas être jeté à l'objet InetOrgPerson
.
Qu'est-ce qui se passe? Je pense propre code d'exemple de Microsoft au travail, mais il n'a pas, si naturellement le code que je suis en train d'écrire sur l'exemple ne fonctionne pas non plus. Quelqu'un at-il fait ce travail?
Merci d'avance! James
La solution
Assurez-vous que l'utilisateur vous recherchez Appartient fait la inetOrgPerson
de classe.