【问题标题】:MVC Model for adding/editing/removing active directory user用于添加/编辑/删除活动目录用户的 MVC 模型
【发布时间】:2017-01-09 05:41:01
【问题描述】:

以下代码:

public string AddADUser(string user_name, string password, string first_name, string last_name, string company_name) {
    try {
        List<ADUser> ADUsers = new List<ADUser>();
        string admin_userName = "Administrator";
        string admin_password = "Password!";
        string domain = "sneaky";
        var context = new PrincipalContext(ContextType.Domain, domain, admin_userName, admin_password);


        UserPrincipal NewUserPrincipal = new UserPrincipal(context, user_name, password, true);

        NewUserPrincipal.UserPrincipalName = user_name;
        NewUserPrincipal.SamAccountName = user_name;
        // company NewUserPrincipal.GetUnderlyingObject.

        NewUserPrincipal.GivenName = first_name;
        NewUserPrincipal.Surname = last_name;
        NewUserPrincipal.DisplayName = user_name;
        NewUserPrincipal.Enabled = true;

        NewUserPrincipal.Save();
        return "User Saved Sucessfully";
    } catch (Exception ex) {
        return "Error saving user: \n" + ex.ToString();
    }
}

产生以下错误:

保存用户时出错:System.DirectoryServices.AccountManagement.PrincipalOperationException:RPC 服务器不可用。 (来自 HRESULT 的异常:0x800706BA)---> System.Runtime.InteropServices.COMException:RPC 服务器不可用。 (来自 HRESULT 的异常:0x800706BA)---内部异常堆栈跟踪结束---在 System.DirectoryServices.AccountManagement.ADStoreCtx.Insert(Principal p) 在 System.DirectoryServices.AccountManagement.Principal.Save() 在 project.Models。 C:\Users\sneakyguy\Desktop\project\project\Models\UserBAL.cs:line 107 中的 UserBAL.AddADUser(String user_name, String password, String first_name, String last_name, String company_name)

奇怪的是我收到另一个用户的访问被拒绝错误,我想也许他没有创建用户的权限......所以我尝试了管理员帐户,现在我收到了这个错误。我知道最终我需要做到这一点,以便执行该操作的用户必须有权在活动目录中创建/编辑和删除用户......而且我也需要知道如何在广告中设置这些权限。我还需要为用户设置公司字段。

【问题讨论】:

    标签: c# asp.net-mvc active-directory


    【解决方案1】:

    The RPC server is unavailable 错误消息表明您的 VS 开发机器难以联系您的域控制器以添加用户。

    【讨论】:

    • 是的。我尝试了之前给出拒绝访问错误的另一个用户/通行证,现在它给出了相同的 RPC 错误......我不知道发生了什么变化,我更改了用户并通过,然后我开始收到这个错误。我知道我可以 ping 服务器。此外,获取系统用户的其他代码区域正在工作,因此它正在与 AD 通信......它仅在我尝试设置新用户时产生此错误。我不确定代码是否正确。
    • 我在 Visual Studio 服务器资源管理器中添加了 AD svr...但它仍然产生相同的错误。
    • 关闭了AD防火墙,没有变化。
    猜你喜欢
    • 2015-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-11
    • 1970-01-01
    相关资源
    最近更新 更多