0

I am using an extension to expose more attributes of the UserPrincipal class (commonly referred to as UserPrincipalEX) to work with AD. The class works great when working with fields like "Department" or "Location". If I try to create a new account using this class I receive an error though "The server was unwilling to process the request". Using the native UserPrincipal class I can create accounts without issue.

Here is the core of the UserPrincipalEX code:

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

1 Answer 1

4

I literally found the answer to this right after I posted the question. I had to modify the following line from <DirectoryObjectClass("Person")> to <DirectoryObjectClass("User")>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.