UserPrincipal SetPassword - 找不到网络路径

时间:2017-11-07 15:19:54

标签: c# active-directory ldap

我正在尝试使用System.DirectoryServices.AccountManagement命名空间更改AD用户密码。下面是我的代码,一切似乎都在工作,我可以在调用FindByIdentity后访问用户属性 - 但是当我尝试调用SetPassword时,抛出以下异常:

Exception has been thrown by the target of an invocation. The network path was not found. (Exception from HRESULT: 0x80070035)

有什么想法吗?这可能是权限问题吗?

    try
    {
        string sDomain = "domain";
        string sDefaultOU = "defaultOU";
        string sServiceUser = "adminUser";
        string sServicePassword = "password";

        using (var context = new PrincipalContext(ContextType.Domain, sDomain, sDefaultOU, sServiceUser, sServicePassword))
        {
            using (var user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, "accountName"))
            {
                // I can access the user properties
                label.Text = user.EmailAddress;
                label.Text = user.LastPasswordSet.ToString();

                // But setting the password throws the exception
                user.SetPassword("newPassword");
                user.Save();
            }
        }
    }
    catch (Exception ex)
    {

    }

1 个答案:

答案 0 :(得分:0)

显然<form action="/your-server-side-code" method="POST"> Coupon Code: <input type="text" name="coupon_code"> <br> <script src="https://checkout.stripe.com/v2/checkout.js" class="stripe-button" data-key="pk_test_czwzkTp2tactuLOEOqbMTRzG" data-amount="2000" data-name="Demo Site" data-description="2 widgets ($20.00)" data-image="/128x128.png"> </script> </form>需要端口445,而简单地访问用户数据却没有。允许此端口解决问题。

相关问题