Estendere UserPrincipal; FindByIdentity () non riesce
-
29-09-2019 - |
Domanda
L'estensione UserPrincipal
per sfruttare la sua built-in proprietà ... incorrere in un problema quando abbiamo sovraccaricare il metodo di FindByIdentity()
.
Da l'esempio di Microsoft all'indirizzo http: // MSDN. microsoft.com/en-us/library/bb384372%28VS.90%29.aspx (parti escluse per brevità):
[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);
}
}
Se prendo il codice esatto dall'esempio MSDN e incollarlo nella mia app, non funziona. La chiamata a rendimenti InetOrgPerson.FindByIdentity()
nullo, in quanto tale:
if (null == InetOrgPerson.FindByIdentity(principalContext, UserName)) {
throw new Exception("bah");
}
In realtà, dal di dentro InetOrgPerson.FindByIdentity()
, la chiamata a rendimenti FindByIdentityWithType()
nullo, in quanto tale:
if (null == FindByIdentityWithType(context, typeof(InetOrgPerson), identityType, identityValue) {
throw new Exception("bah");
}
Tuttavia, la chiamata:
FindByIdentityWithType(context, typeof(UserPrincipal), identityType, identityValue)
mi dà l'oggetto utente che voglio. Tranne che non posso usare quello, perché non può essere lanciato all'oggetto InetOrgPerson
ho bisogno di tornare.
Che cosa dà? Mi aspetto proprio codice di esempio di Microsoft al lavoro, ma non lo fa, così naturalmente il codice che sto cercando di scrivere sulla base dell'esempio non funziona, neanche. Qualcuno ha fatto questo lavoro?
Grazie in anticipo! James
Soluzione
Assicurarsi che l'utente si sta cercando in realtà appartiene alla classe di inetOrgPerson
.