2014-09-08 6 views
0

Я использую расширение для отображения дополнительных атрибутов класса UserPrincipal (обычно называемого UserPrincipalEX) для работы с AD. Класс отлично работает при работе с такими полями, как «Отдел» или «Местоположение». Если я попытаюсь создать новую учетную запись с использованием этого класса, я получаю сообщение об ошибке, хотя «сервер не захотел обработать запрос». Используя собственный класс UserPrincipal, я могу создавать учетные записи без проблем.Создайте нового пользователя с помощью UserPrincipalEX

Вот ядро ​​кода UserPrincipalEX:

Imports System.DirectoryServices.AccountManagement 

<DirectoryRdnPrefix("CN")> _ 
<DirectoryObjectClass("Person")> _ 
Public Class UserPrincipalEx 
Inherits UserPrincipal 

Public Sub New(context As PrincipalContext) 
    MyBase.New(context) 
End Sub 


Public Sub New(context As PrincipalContext, samAccountName As String, password As String, enabled As Boolean) 
    MyBase.New(context, samAccountName, password, enabled) 
End Sub 

Public Shared Shadows Function FindByIdentity(context As PrincipalContext, identityValue As String) As UserPrincipalEx 
    Return DirectCast(FindByIdentityWithType(context, GetType(UserPrincipalEx), identityValue), UserPrincipalEx) 
End Function 

Public Shared Shadows Function FindByIdentity(context As PrincipalContext, identityType As IdentityType, identityValue As String) As UserPrincipalEx 
    Return DirectCast(FindByIdentityWithType(context, GetType(UserPrincipalEx), identityType, identityValue), UserPrincipalEx) 
End Function 

<DirectoryProperty("Company")> _ 
Public Property Company() As String 
    Get 
     If ExtensionGet("company").Length <> 1 Then 
      Return String.Empty 
     End If 

     Return DirectCast(ExtensionGet("company")(0), String) 
    End Get 
    Set(value As String) 
     ExtensionSet("company", value) 
    End Set 

End Property 

End Class 

ответ

4

Я буквально нашел ответ на это право после того, как я отправил вопрос. Мне пришлось изменить следующую строку от <DirectoryObjectClass("Person")> до <DirectoryObjectClass("User")>

Смежные вопросы