【问题标题】:Principal Extension for UserPrincipal in .NET throwing an "Unwilling to process request" error.NET 中 UserPrincipal 的主体扩展引发“不愿意处理请求”错误
【发布时间】:2018-10-08 19:54:12
【问题描述】:

我正在尝试使用我的 VB.NET 可执行文件在 AD 中设置扩展属性的值。我扩展了 UserPrincipal 类来完成此操作,但现在出现错误

服务器不愿意处理请求

当我尝试设置扩展属性时。

我可以从 AD 中的现有用户那里获取该属性而不会出现任何错误,并且当我尝试在没有扩展类的情况下创建和保存用户时,它可以工作。

        Dim stringDomainName As String = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName
        Dim objPrincipalContext As New PrincipalContext(ContextType.Domain, stringDomainName, DirectoryPath, ContextOptions.SimpleBind, DomainUsername, DomainPassword)
        Dim objUserPrincipal As New UPExtention(objPrincipalContext, sUserName, sPassword, True)

        Dim expDate As Date

        'Set Name
        objUserPrincipal.Name = sFirstName & " " & sLastName
        'Set First Name
        objUserPrincipal.GivenName = sFirstName
        'Set Last Name
        objUserPrincipal.Surname = sLastName
        'Set Display Name
        objUserPrincipal.DisplayName = sLastName & ", " & sFirstName
        'Enable Account
        objUserPrincipal.Enabled = True
        objUserPrincipal.extentionAttribute15 = sUserName

        'Save the created user
        objUserPrincipal.Save(objPrincipalContext)

【问题讨论】:

    标签: .net vb.net active-directory userprincipal principalcontext


    【解决方案1】:

    我不能 100% 确定导致错误的原因,但我返回使用未扩展的 UserPrincipal 类来创建初始对象并在未设置扩展属性的情况下保存它。然后我创建了扩展 UserPrincipal 的对象,并使用重载的 FindByIdentity 函数来获取我刚刚创建的用户,然后设置扩展属性并再次保存。现在可以了!

    【讨论】:

      猜你喜欢
      • 2019-03-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-30
      相关资源
      最近更新 更多