【发布时间】: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