在asp.net c#中的活动目录中创建用户时,我们在活动目录中嵌套了OU,如何提供识别OU的路径?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9531640/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to give path to identify OU when we have nested OU's in active directory while creating a user in active directory in asp.net c#?
提问by RL89
Using
使用
PrincipalContext pc = new PrincipalContext(ContextType.Domain, "me.com", "OU=Menetwork OU=Users OU=IT")
I am working on directory programing and I want to know how can I give path for OU when we have nested OUs in active directory while creating a User in active Directory.
我正在从事目录编程,我想知道如何在活动目录中嵌套 OU 时为 OU 提供路径,同时在活动目录中创建用户。
采纳答案by JPBlanc
A Directory is a tree of objects. Each object OUs (containers), user (leaf in your case) is addressed by a distinguished name wich is composed by an attribute=valuepair suffixed by the distinguished name of his container. The following two screenshots show you the two visions, MMC one and the LDAP one with all the DNs.
目录是对象树。每个对象 OU(容器)、用户(在您的情况下是叶子)都由一个专有名称寻址,该名称由一attribute=value对以容器的专有名称为后缀的对组成。以下两个屏幕截图向您展示了两种愿景,一种是 MMC,一种是带有所有 DN 的 LDAP。




In my case here is how I can create a user in an nested OU like this :
就我而言,这是我如何在嵌套 OU 中创建用户的方法,如下所示:
/* Creating a user
* Retreiving a principal context
*/
PrincipalContext domainContextMonou = new PrincipalContext(ContextType.Domain, "WM2008R2ENT:389", "ou=SousMonou,ou=Monou,dc=dom,dc=fr", "user", "pass");
/* Create a user principal object
*/
UserPrincipal aSlxUser = new slxUser(domainContextMonou, "user3.users", "pass@1w0rd01", true);
/* assign some properties to the user principal
*/
aSlxUser.GivenName = "user3";
aSlxUser.Surname = "users";
/* Force the user to change password at next logon
*/
//aSlxUser.ExpirePasswordNow();
/* save the user to the directory
*/
aSlxUser.Save();
/* set the password to a new value
*/
aSlxUser.SetPassword("test.2013");
aSlxUser.Save();

