如何在C# asp.net中在window server 2003上创建系统用户?
您好,我想在 Windows Server 2003 活动目录中创建一个系统用户,我使用以下 C# 代码,
DirectoryEntry AD = new DirectoryEntry("WinNT://"+Environment.MachineName+",computer");
DirectoryEntry NewUser = AD.Children.Add(username, "user");
NewUser.Invoke("SetPassword", new object[] { password });
NewUser.Invoke("Put", new object[] { "Description", "Test User from .NET"});
NewUser.CommitChanges();
DirectoryEntry grp;
grp = AD.Children.Find("Guests", "group");
if (grp != null)
{
grp.Invoke("Add", new object[] { NewUser.Path.ToString() });
}
当我在 VisualY Studio Web 引擎上本地运行此应用程序时,此代码使用户成为用户,但当我在 Windows Server 2003 上的 IIS 上部署此应用程序时,此代码使用户成为用户会给出异常
异常:
General Access Denied Error
请帮助我我做错了什么,在窗口服务器中创建用户需要哪些权限以及我们如何授予此权限。谢谢。
Hi i want to create a system user in window server 2003 active directory for which i use following C# code ,
DirectoryEntry AD = new DirectoryEntry("WinNT://"+Environment.MachineName+",computer");
DirectoryEntry NewUser = AD.Children.Add(username, "user");
NewUser.Invoke("SetPassword", new object[] { password });
NewUser.Invoke("Put", new object[] { "Description", "Test User from .NET"});
NewUser.CommitChanges();
DirectoryEntry grp;
grp = AD.Children.Find("Guests", "group");
if (grp != null)
{
grp.Invoke("Add", new object[] { NewUser.Path.ToString() });
}
this code makes user when i run this application locally on visualy studio web engine but when i deploy this application on iis on window server 2003 this will give exception
Exception:
General Access Denied Error
kindly help me what im doing wrong which permission is required to create user in window server and how we give this perssion. thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 System.DirectoryServices.AccountManagement 命名空间。利用其中的类,您可以通过以下方式执行此操作:
此外,您可以在应用程序上配置模拟,并跳过 PrimaryContext 构造函数异常中的所有参数(如果此功能仅允许管理员使用),则跳过第一个参数。
Look at System.DirectoryServices.AccountManagement namespace. Utilizing classes from it you can do this in such way:
Also, you may configure impersonation on your application and skip all parameters in the PrincipalContext constructor exception the first one if this functionality allowed for administrators only.