我正在使用扩展来公开UserPrincipal类的更多属性(通常称为UserPrincipalEX)以使用AD。使用“部门”或“位置”等字段时,该课程效果很好。如果我尝试使用此类创建一个新帐户,我收到错误,但“服务器不愿意处理请求”。使用本机UserPrincipal类,我可以毫无问题地创建帐户。
以下是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
答案 0 :(得分:4)
在我发布问题之后,我确实找到了答案。我必须修改从<DirectoryObjectClass("Person")>
到<DirectoryObjectClass("User")>