在Active Directory中创建用户:连接到系统的设备无法运行

问题描述 投票:30回答:1

请考虑此代码尝试创建Active Directory帐户。它在这里使用一组数据生成异常。目前尚不清楚导致异常的原因。

 var user = new UserPrincipal(someValidUserContext,
                              ".x-xyz-t-FooFooBarTest", "somePwd", true);

 user.UserPrincipalName = "[email protected]";
 user.SamAccountName = ".x-xyz-t-FooFooBarTest";         
 user.DisplayName = "Some String 16 chars long";
 user.Name =  "Some String 16 chars long";
 user.Description = "Foo BarBaz 12 more characters";
 user.AccountExpirationDate = someDateInFuture;
 user.UserCannotChangePassword = true;
 user.Save();

 // exception thrown on Save(): 
 // A device attached to the system is not functioning

用户代码未处理PrincipalOperationException:连接到系统的设备无法运行

造成这种异常的原因是什么,你如何解决这个问题?

c# active-directory asp.net-3.5
1个回答
65
投票

sAMAccountName属性必须为20个字符或更少。

© www.soinside.com 2019 - 2024. All rights reserved.