Reputation: 3358
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
Upvotes: 0
Views: 1304
Reputation: 3358
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")>
Upvotes: 4