Расширение 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 ()
, вызов FindByIdentityWithT 11127237] возвращает значение null, как таковое:
if (null == FindByIdentityWithType(context, typeof(InetOrgPerson), identityType, identityValue) {
throw new Exception("bah");
}
Однако вызов:
FindByIdentityWithType(context, typeof(UserPrincipal), identityType, identityValue)
дает мне нужный объект пользователя. За исключением того, что я не могу использовать это, потому что это может не может быть приведен к объекту InetOrgPerson
, который мне нужно вернуть.
Что дает? Я ожидаю, что собственный пример кода Microsoft будет работать, но это не так, поэтому естественно, что код, который я пытаюсь написать на основе примера, тоже не работает. Кто-нибудь сделал эту работу?
Заранее спасибо! Джеймс
Убедитесь, что пользователь, которого вы ищете, действительно принадлежит к классу inetOrgPerson
.