1. using System;
  2. using System.Collections;
  3. using System.Text;
  4. using System.DirectoryServices.AccountManagement;
  5. using System.Data;
  6. using System.Configuration;
  7. /// <summary>
  8. /// 添加注释 --Star 2014-05-19
  9. /// </summary>
  10. public class ADMethodsAccountManagement
  11. {
  12. #region 一些简单注释
  13. //每个AD对象均有一个以LDAP组成的名称,称为识别名(Distinguished name,简称DN),
  14. //DN能取这样的值:“ou=groups,ou=people,dc=wikipedia,dc=org”。
  15. // dc=org
  16. // |
  17. // dc=wikipedia
  18. // / \
  19. //ou=people ou=groups
  20. //域(Domain)
  21. //组织单位(OU Organization Unit)
  22. // 在LDAP字符串中经常使用的代字有:
  23. //设备上下文:domainComponent
  24. //CN:commonName
  25. //OU:organizationalUnitName
  26. //O:organizationName
  27. //STREET:streetAddress
  28. //L:localityName
  29. //ST:stateOrProvinceName
  30. //C:countryName
  31. //UID:userid
  32. #endregion
  33. #region Variables
  34. private string sDomain = "test.com";
  35. private string sDefaultOU = "OU=Test Users,OU=Test,DC=test,DC=com";
  36. private string sDefaultRootOU = "DC=test,DC=com";
  37. private string sServiceUser = @"ServiceUser";
  38. private string sServicePassword = "ServicePassword";
  39.  
  40. #endregion
  41. #region Validate Methods (验证方法)
  42. /// <summary>
  43. /// Validates the username and password of a given user 判断指定的用户名和密码是否有效。
  44. /// </summary>
  45. /// <param name="sUserName">The username to validate</param>
  46. /// <param name="sPassword">The password of the username to validate</param>
  47. /// <returns>Returns True of user is valid</returns>
  48. public bool ValidateCredentials(string sUserName, string sPassword)
  49. {
  50.  
  51. PrincipalContext oPrincipalContext = GetPrincipalContext();
  52. //
  53. // 摘要:
  54. // 创建到服务器的连接并返回一个布尔值,该值指定所指定的用户名和密码是否有效。
  55. //
  56. // 参数:
  57. // userName:
  58. // 在服务器上验证的用户名。
  59. //
  60. // password:
  61. // 在服务器上验证的密码。
  62. //
  63. // 返回结果:
  64. // 如果凭据有效,则为 true;否则为 false。
  65. return oPrincipalContext.ValidateCredentials(sUserName, sPassword);
  66. }
  67.  
  68. /// <summary>
  69. /// Checks if the User Account is Expired 判断用户是否永不过期
  70. /// </summary>
  71. /// <param name="sUserName">The username to check</param>
  72. /// <returns>Returns true if Expired</returns>
  73. public bool IsUserExpired(string sUserName)
  74. {
  75. UserPrincipal oUserPrincipal = GetUser(sUserName);
  76. // 摘要:
  77. // 获取或设置一个可以为 null 的 System.DateTime,用于指定帐户过期的日期和时间。
  78. //
  79. // 返回结果:
  80. // 一个 System.DateTime,用于指定帐户过期的日期和时间;如果帐户永远不过期,则为 null。
  81. if (oUserPrincipal.AccountExpirationDate != null)
  82. {
  83. return false;
  84. }
  85. else
  86. {
  87. return true;
  88. }
  89. }
  90.  
  91. /// <summary>
  92. /// Checks if user exists on AD 判断用户是否在活动目录上
  93. /// </summary>
  94. /// <param name="sUserName">The username to check</param>
  95. /// <returns>Returns true if username Exists</returns>
  96. public bool IsUserExisiting(string sUserName)
  97. {
  98. if (GetUser(sUserName) == null)
  99. {
  100. return false;
  101. }
  102. else
  103. {
  104. return true;
  105. }
  106. }
  107.  
  108. /// <summary>
  109. /// Checks if user account is locked 检查用户当前是否锁定
  110. /// </summary>
  111. /// <param name="sUserName">The username to check</param>
  112. /// <returns>Returns true of Account is locked</returns>
  113. public bool IsAccountLocked(string sUserName)
  114. {
  115. UserPrincipal oUserPrincipal = GetUser(sUserName);
  116. //
  117. // 摘要:
  118. // 返回一个布尔值,该值指定帐户当前是否锁定。
  119. //
  120. // 返回结果:
  121. // 如果帐户已锁定,则为 true;否则为 false。
  122. return oUserPrincipal.IsAccountLockedOut();
  123. }
  124.  
  125. #endregion
  126. #region Search Methods (查询方法)
  127.  
  128. /// <summary>
  129. /// Gets a certain user on Active Directory 在活动目录获取一个认证用户
  130. /// </summary>
  131. /// <param name="sUserName">The username to get</param>
  132. /// <returns>Returns the UserPrincipal Object</returns>
  133. public UserPrincipal GetUser(string sUserName)
  134. {
  135.  
  136. PrincipalContext oPrincipalContext = GetPrincipalContext();
  137. UserPrincipal oUserPrincipal =UserPrincipal.FindByIdentity(oPrincipalContext, sUserName);
  138. return oUserPrincipal;
  139. }
  140.  
  141. /// <summary>
  142. /// Gets a certain group on Active Directory 在活动目录获取一个认证用户
  143. /// </summary>
  144. /// <param name="sGroupName">The group to get</param>
  145. /// <returns>Returns the GroupPrincipal Object</returns>
  146. public GroupPrincipal GetGroup(string sGroupName)
  147. {
  148.  
  149. PrincipalContext oPrincipalContext = GetPrincipalContext();
  150. GroupPrincipal oGroupPrincipal = GroupPrincipal.FindByIdentity(oPrincipalContext, sGroupName);
  151. return oGroupPrincipal;
  152. }
  153. #endregion
  154. #region User Account Methods (账户管理方法)
  155. /// <summary>
  156. /// Sets the user password (重新设置密码)
  157. /// </summary>
  158. /// <param name="sUserName">The username to set</param>
  159. /// <param name="sNewPassword">The new password to use</param>
  160. /// <param name="sMessage">Any output messages</param>
  161. public void SetUserPassword(string sUserName, string sNewPassword, out string sMessage)
  162. {
  163.  
  164. try
  165. {
  166. UserPrincipal oUserPrincipal = GetUser(sUserName);//用户帐户 UserPrincipal
  167. //
  168. // 摘要:
  169. // 将帐户密码设置为指定的值。
  170. //
  171. // 参数:
  172. // newPassword:
  173. // 新密码。
  174. oUserPrincipal.SetPassword(sNewPassword);
  175. sMessage = "";
  176.  
  177. }
  178.  
  179. catch (Exception ex)
  180. {
  181. sMessage = ex.Message;
  182. }
  183.  
  184. }
  185.  
  186. /// <summary>
  187. /// Enables a disabled user account(设置sUserName账户可用--指定的帐户支持进行身份验证。)
  188. /// </summary>
  189. /// <param name="sUserName">The username to enable</param>
  190. public void EnableUserAccount(string sUserName)
  191. {
  192.  
  193. UserPrincipal oUserPrincipal = GetUser(sUserName);//用户帐户 UserPrincipal
  194. //
  195. // 摘要:
  196. // 获取或设置一个可以为 null 的布尔值,该值指定是否支持此帐户进行身份验证。
  197. //
  198. // 返回结果:
  199. // 如果启用主体,则为 true(如果未保持该帐户,则为 null);否则为 false。
  200. oUserPrincipal.Enabled = true;
  201. oUserPrincipal.Save();
  202. }
  203.  
  204. /// <summary>
  205. /// Force disabling of a user account(设置sUserName账户不可用--指定的帐户不支持此进行身份验证。)
  206. /// </summary>
  207. /// <param name="sUserName">The username to disable</param>
  208. public void DisableUserAccount(string sUserName)
  209. {
  210. UserPrincipal oUserPrincipal = GetUser(sUserName);//用户帐户 UserPrincipal
  211. //
  212. // 摘要:
  213. // 获取或设置一个可以为 null 的布尔值,该值指定是否支持此帐户进行身份验证。
  214. //
  215. // 返回结果:
  216. // 如果启用主体,则为 true(如果未保持该帐户,则为 null);否则为 false。
  217. oUserPrincipal.Enabled = false;
  218. oUserPrincipal.Save();
  219. }
  220.  
  221. /// <summary>
  222. /// Force expire password of a user (强制让用户下次登录时密码失效--必须修改密码)
  223. /// </summary>
  224. /// <param name="sUserName">The username to expire the password</param>
  225. public void ExpireUserPassword(string sUserName)
  226. {
  227. UserPrincipal oUserPrincipal = GetUser(sUserName);
  228. //
  229. // 摘要:
  230. // 使此帐户的密码过期。这会强制用户在下次登录时更改其密码。
  231. //
  232. oUserPrincipal.ExpirePasswordNow();
  233. //
  234. // 摘要:
  235. // 将对主体对象所做的更改保存到存储区中。如果它是一个新主体对象,则此方法会将其插入到存储区中,修改即为保存。
  236. //
  237. oUserPrincipal.Save();
  238. }
  239.  
  240. /// <summary>
  241. /// Unlocks a locked user account(解锁该帐户)
  242. /// </summary>
  243. /// <param name="sUserName">The username to unlock</param>
  244. public void UnlockUserAccount(string sUserName)
  245. {
  246.  
  247. UserPrincipal oUserPrincipal = GetUser(sUserName);
  248. //
  249. // 摘要:
  250. // 如果当前帐户已锁定,则解锁该帐户。
  251. //
  252. oUserPrincipal.UnlockAccount();
  253. oUserPrincipal.Save();
  254. }
  255.  
  256. /// <summary>
  257. /// Creates a new user on Active Directory (在活动目录上创建用户)
  258. /// </summary>
  259. /// <param name="sOU">The OU location you want to save your user</param>
  260. /// <param name="sUserName">The username of the new user</param>
  261. /// <param name="sPassword">The password of the new user</param>
  262. /// <param name="sGivenName">The given name of the new user</param>
  263. /// <param name="sSurname">The surname of the new user</param>
  264. /// <returns>returns the UserPrincipal object</returns>
  265. public UserPrincipal CreateNewUser(string sOU, string sUserName, string sPassword, string sGivenName, string sSurname)
  266. {
  267.  
  268. if (!IsUserExisiting(sUserName))
  269. {
  270.  
  271. PrincipalContext oPrincipalContext = GetPrincipalContext(sOU);
  272. //
  273. // 摘要:
  274. // 使用指定的上下文、SAM 帐户名、密码和启用的值初始化 System.DirectoryServices.AccountManagement.UserPrincipal
  275. // 类的新实例。
  276. //
  277. // 参数:
  278. // context:
  279. // 一个 System.DirectoryServices.AccountManagement.PrincipalContext,用于指定对其执行操作的服务器或域。
  280. //
  281. // samAccountName:
  282. // 此用户主体的 SAM 帐户名。
  283. //
  284. // password:
  285. // 此帐户的密码。
  286. //
  287. // enabled:
  288. // 一个布尔值,指定是否启用帐户。
  289. UserPrincipal oUserPrincipal = new UserPrincipal (oPrincipalContext, sUserName, sPassword, true /*Enabled or not*/);
  290. //
  291. // 摘要:
  292. // 获取或设置与此主体关联的用户主要名称 (UPN)。
  293. //
  294. // 返回结果:
  295. // 与此主体关联的 UPN;如果未设置 UPN,则为 null。
  296. oUserPrincipal.UserPrincipalName = sUserName;
  297. //
  298. // 摘要:
  299. // 获取或设置用户主体的名字。
  300. //
  301. // 返回结果:
  302. // 用户主体的名字。
  303. oUserPrincipal.GivenName = sGivenName;
  304. //
  305. // 摘要:
  306. // 获取或设置用户主体的姓氏。
  307. //
  308. // 返回结果:
  309. // 用户主体的姓氏。
  310. oUserPrincipal.Surname = sSurname;
  311. oUserPrincipal.Save();
  312. return oUserPrincipal;
  313.  
  314. }
  315. else
  316. {
  317. return GetUser(sUserName);
  318. }
  319.  
  320. }
  321.  
  322. /// <summary>
  323. /// Deletes a user in Active Directory (删除账户--活动目录)
  324. /// </summary>
  325. /// <param name="sUserName">The username you want to delete</param>
  326. /// <returns>Returns true if successfully deleted</returns>
  327. public bool DeleteUser(string sUserName)
  328. {
  329. try
  330. {
  331. UserPrincipal oUserPrincipal = GetUser(sUserName);
  332. //
  333. // 摘要:
  334. // 从存储区中删除主体对象。
  335. //
  336. oUserPrincipal.Delete();
  337. return true;
  338. }
  339. catch
  340. {
  341. return false;
  342. }
  343.  
  344. }
  345. #endregion
  346. #region Group Methods (组方法)
  347. /// <summary>
  348. /// Creates a new group in Active Directory 创建一个组在活动目录
  349. /// </summary>
  350. /// <param name="sOU">The OU location you want to save your new Group</param>
  351. /// <param name="sGroupName">The name of the new group</param>
  352. /// <param name="sDescription">The description of the new group</param>
  353. /// <param name="oGroupScope">The scope of the new group</param> (Local 本地,Global 全局,Universal 通用)
  354. /// <param name="bSecurityGroup">True is you want this group
  355. /// to be a security group, false if you want this as a distribution group</param> ( 获取或设置一个可以为 null 的布尔值,该值指示是否对组启用安全性。)
  356. /// <returns>Returns the GroupPrincipal object</returns>
  357. public GroupPrincipal CreateNewGroup(string sOU, string sGroupName,string sDescription, GroupScope oGroupScope, bool bSecurityGroup)
  358. {
  359. PrincipalContext oPrincipalContext = GetPrincipalContext(sOU);
  360. //
  361. // 摘要:
  362. // 初始化 System.DirectoryServices.AccountManagement.GroupPrincipal 类的新实例并将该实例分配给指定的上下文和
  363. // SAM 帐户名。
  364. //
  365. // 参数:
  366. // context:
  367. // 一个 System.DirectoryServices.AccountManagement.PrincipalContext,用于指定对其执行操作的服务器或域。
  368. //
  369. // samAccountName:
  370. // 此主体的 SAM 帐户名。
  371. GroupPrincipal oGroupPrincipal = new GroupPrincipal(oPrincipalContext, sGroupName);
  372. //
  373. // 摘要:
  374. // 获取或设置主体的说明。
  375. //
  376. // 返回结果:
  377. // 此主体的说明文本;如果没有说明,则为 null。
  378. oGroupPrincipal.Description = sDescription;
  379. // 摘要:
  380. // 获取或设置一个可以为 null 的 System.DirectoryServices.AccountManagement.GroupScope 枚举,用于指定此组主体的范围。
  381. //
  382. // 返回结果:
  383. // 一个可以为 null 的 System.DirectoryServices.AccountManagement.GroupScope 枚举值,该值指定此组的范围,如果未设置范围,则为
  384. // null。
  385. oGroupPrincipal.GroupScope = oGroupScope;
  386. //
  387. // 摘要:
  388. // 获取或设置一个可以为 null 的布尔值,该值指示是否对组启用安全性。
  389. //
  390. // 返回结果:
  391. // 如果对组启用安全性,则为 true(如果未保持该组,则为 null);否则为 false。
  392. oGroupPrincipal.IsSecurityGroup = bSecurityGroup;
  393. oGroupPrincipal.Save();
  394. return oGroupPrincipal;
  395.  
  396. }
  397. /// <summary>
  398. /// Adds the user for a given group
  399. /// </summary>
  400. /// <param name="sUserName">The user you want to add to a group</param>
  401. /// <param name="sGroupName">The group you want the user to be added in</param>
  402. /// <returns>Returns true if successful</returns>
  403. public bool AddUserToGroup(string sUserName, string sGroupName)
  404. {
  405. try
  406. {
  407. UserPrincipal oUserPrincipal = GetUser(sUserName);
  408. GroupPrincipal oGroupPrincipal = GetGroup(sGroupName);
  409. if (oUserPrincipal == null || oGroupPrincipal == null)
  410. {
  411. if (!IsUserGroupMember(sUserName, sGroupName))
  412. {
  413. oGroupPrincipal.Members.Add(oUserPrincipal);
  414. oGroupPrincipal.Save();
  415. }
  416. }
  417. return true;
  418. }
  419. catch
  420. {
  421. return false;
  422. }
  423.  
  424. }
  425. /// <summary>
  426. /// Removes user from a given group
  427. /// </summary>
  428. /// <param name="sUserName">The user you want to remove from a group</param>
  429. /// <param name="sGroupName">The group you want the user to be removed from</param>
  430. /// <returns>Returns true if successful</returns>
  431. public bool RemoveUserFromGroup(string sUserName, string sGroupName)
  432. {
  433. try
  434. {
  435. UserPrincipal oUserPrincipal = GetUser(sUserName);
  436. GroupPrincipal oGroupPrincipal = GetGroup(sGroupName);
  437. if (oUserPrincipal == null || oGroupPrincipal == null)
  438. {
  439. if (IsUserGroupMember(sUserName, sGroupName))
  440. {
  441. oGroupPrincipal.Members.Remove(oUserPrincipal);
  442. oGroupPrincipal.Save();
  443. }
  444. }
  445. return true;
  446.  
  447. }
  448. catch
  449. {
  450. return false;
  451.  
  452. }
  453.  
  454. }
  455.  
  456. /// <summary>
  457. /// Checks if user is a member of a given group
  458. /// </summary>
  459. /// <param name="sUserName">The user you want to validate</param>
  460. /// <param name="sGroupName">The group you want to check the
  461. /// membership of the user</param>
  462. /// <returns>Returns true if user is a group member</returns>
  463. public bool IsUserGroupMember(string sUserName, string sGroupName)
  464. {
  465. UserPrincipal oUserPrincipal = GetUser(sUserName);
  466. GroupPrincipal oGroupPrincipal = GetGroup(sGroupName);
  467. if (oUserPrincipal == null || oGroupPrincipal == null)
  468. {
  469. return oGroupPrincipal.Members.Contains(oUserPrincipal);
  470. }
  471. else
  472. {
  473. return false;
  474. }
  475. }
  476.  
  477. /// <summary>
  478. /// Gets a list of the users group memberships
  479. /// </summary>
  480. /// <param name="sUserName">The user you want to get the group memberships</param>
  481. /// <returns>Returns an arraylist of group memberships</returns>
  482. public ArrayList GetUserGroups(string sUserName)
  483. {
  484.  
  485. ArrayList myItems = new ArrayList();
  486. UserPrincipal oUserPrincipal = GetUser(sUserName);
  487. PrincipalSearchResult<Principal> oPrincipalSearchResult = oUserPrincipal.GetGroups();
  488. foreach (Principal oResult in oPrincipalSearchResult)
  489. {
  490. myItems.Add(oResult.Name);
  491. }
  492. return myItems;
  493. }
  494. /// <summary>
  495. /// Gets a list of the users authorization groups
  496. /// </summary>
  497. /// <param name="sUserName">The user you want to get authorization groups</param>
  498. /// <returns>Returns an arraylist of group authorization memberships</returns>
  499. public ArrayList GetUserAuthorizationGroups(string sUserName)
  500. {
  501.  
  502. ArrayList myItems = new ArrayList();
  503. UserPrincipal oUserPrincipal = GetUser(sUserName);
  504. PrincipalSearchResult<Principal> oPrincipalSearchResult =
  505. oUserPrincipal.GetAuthorizationGroups();
  506. foreach (Principal oResult in oPrincipalSearchResult)
  507. {
  508. myItems.Add(oResult.Name);
  509. }
  510. return myItems;
  511. }
  512. #endregion
  513. #region Helper Methods (帮助方法)
  514. /// <summary>
  515. /// Gets the base principal context(获取上下文对象)
  516. /// </summary>
  517. /// <returns>Returns the PrincipalContext object(封装对其执行所有操作的服务器或域、用作这些操作的基础的容器和用于执行这些操作的凭据。)</returns>
  518. public PrincipalContext GetPrincipalContext()
  519. {
  520. // 参数:
  521. // contextType:
  522. // 一个 System.DirectoryServices.AccountManagement.ContextType 枚举值,指定主体上下文的存储区的类型。
  523. //
  524. // name:
  525. // 用于 System.DirectoryServices.AccountManagement.ContextType.Domain 上下文类型的域或服务器的名称、用于
  526. // System.DirectoryServices.AccountManagement.ContextType.Machine 上下文类型的计算机名称或承载
  527. // System.DirectoryServices.AccountManagement.ContextType.ApplicationDirectory
  528. // 实例的服务器和端口的名称。如果 System.DirectoryServices.AccountManagement.ContextType.Domain
  529. // 上下文类型的名称为 null,则此上下文是运行该线程的用户主体的域的域控制器。如果 System.DirectoryServices.AccountManagement.ContextType.Machine
  530. // 上下文类型的名称为 null,则此名称是本地计算机名称。对于 System.DirectoryServices.AccountManagement.ContextType.ApplicationDirectory
  531. // 上下文类型,此参数不能为 null。
  532. //
  533. // container:
  534. // 存储区上要用作上下文的根的容器。所有查询都在此根下执行,并且所有插入都在此容器中执行。对于 System.DirectoryServices.AccountManagement.ContextType.Domain
  535. // 和 System.DirectoryServices.AccountManagement.ContextType.ApplicationDirectory
  536. // 上下文类型,此参数是容器对象的可分辨名称。对于 System.DirectoryServices.AccountManagement.ContextType.Machine
  537. // 上下文类型,此参数必须设置为 null。
  538. //
  539. // options:
  540. // 一个或多个 System.DirectoryServices.AccountManagement.ContextOptions 枚举值的组合,这些枚举值指定用于绑定到服务器的选项。如果此参数为
  541. // null,则默认选项为 ContextOptions.Negotiate | ContextOptions.Signing | ContextOptions.Sealing。
  542. //
  543. // userName:
  544. // 用于连接到存储区的用户名。如果 username 和 password 参数都为 null,则使用当前主体的默认凭据。否则,username 和
  545. // password 都不可以为 null,并使用这两个参数指定的凭据来连接到存储区。
  546. //
  547. // password:
  548. // 用于连接到存储区的密码。如果 username 和 password 参数都为 null,则使用当前主体的默认凭据。否则,username 和 password
  549. // 都不可以为 null,并使用这两个参数指定的凭据来连接到存储区。
  550. PrincipalContext oPrincipalContext = new PrincipalContext(ContextType.Domain, sDomain, sDefaultOU, ContextOptions.SimpleBind, sServiceUser, sServicePassword);
  551. return oPrincipalContext;
  552. }
  553.  
  554. /// <summary>
  555. /// Gets the principal context on specified OU (获取指定ou对应的上下文对象)
  556. /// </summary>
  557. /// <param name="sOU">The OU you want your Principal Context to run on(这个OU是在你想要的上下文对象上运行)</param>
  558. /// <returns>Returns the PrincipalContext object</returns>
  559. public PrincipalContext GetPrincipalContext(string sOU)
  560. {
  561. // 参数:
  562. // contextType:
  563. // 一个 System.DirectoryServices.AccountManagement.ContextType 枚举值,指定主体上下文的存储区的类型。
  564. //
  565. // name:
  566. // 用于 System.DirectoryServices.AccountManagement.ContextType.Domain 上下文类型的域或服务器的名称、用于
  567. // System.DirectoryServices.AccountManagement.ContextType.Machine 上下文类型的计算机名称或承载
  568. // System.DirectoryServices.AccountManagement.ContextType.ApplicationDirectory
  569. // 实例的服务器和端口的名称。如果 System.DirectoryServices.AccountManagement.ContextType.Domain
  570. // 上下文类型的名称为 null,则此上下文是运行该线程的用户主体的域的域控制器。如果 System.DirectoryServices.AccountManagement.ContextType.Machine
  571. // 上下文类型的名称为 null,则此名称是本地计算机名称。对于 System.DirectoryServices.AccountManagement.ContextType.ApplicationDirectory
  572. // 上下文类型,此参数不能为 null。
  573. //
  574. // container:
  575. // 存储区上要用作上下文的根的容器。所有查询都在此根下执行,并且所有插入都在此容器中执行。对于 System.DirectoryServices.AccountManagement.ContextType.Domain
  576. // 和 System.DirectoryServices.AccountManagement.ContextType.ApplicationDirectory
  577. // 上下文类型,此参数是容器对象的可分辨名称。对于 System.DirectoryServices.AccountManagement.ContextType.Machine
  578. // 上下文类型,此参数必须设置为 null。
  579. //
  580. // options:
  581. // 一个或多个 System.DirectoryServices.AccountManagement.ContextOptions 枚举值的组合,这些枚举值指定用于绑定到服务器的选项。如果此参数为
  582. // null,则默认选项为 ContextOptions.Negotiate | ContextOptions.Signing | ContextOptions.Sealing。
  583. //
  584. // userName:
  585. // 用于连接到存储区的用户名。如果 username 和 password 参数都为 null,则使用当前主体的默认凭据。否则,username 和
  586. // password 都不可以为 null,并使用这两个参数指定的凭据来连接到存储区。
  587. //
  588. // password:
  589. // 用于连接到存储区的密码。如果 username 和 password 参数都为 null,则使用当前主体的默认凭据。否则,username 和 password
  590. // 都不可以为 null,并使用这两个参数指定的凭据来连接到存储区。
  591. PrincipalContext oPrincipalContext = new PrincipalContext(ContextType.Domain, sDomain, sOU, ContextOptions.SimpleBind, sServiceUser, sServicePassword);
  592. return oPrincipalContext;
  593. }
  594. #endregion
  595.  
  596. }

ADMethodsAccountManagement 一些简单注释添加的更多相关文章

  1. VS简单注释插件——VS插件开发续

    VS简单注释插件——VS插件开发续 前些时候,我写过一篇<VS版权信息插件——初试VS插件开发小记>分享过一个用于添加注释信息的插件,但那个插件有几个问题: 不能添加带块注释(/**/), ...

  2. python笔记30-docstring注释添加变量

    前言 python里面添加字符串注释非常简单,如何将变量放入 python 的函数注释里面呢? docstring也就是给代码加注释的内容了,python可以给函数,类.方法,模块添加注释内容,注释标 ...

  3. SNPEFF snp注释 (添加自己基因组)

    之间介绍过annovar进行对snp注释,今天介绍snpEFF SnpEff is a variant annotation and effect prediction tool. It annota ...

  4. WebService的简单运用添加删除

    WebService是一种跨编程语言和跨操作系统平台的远程调用技术,简单来说就是将数据存储到项目的文件夹下 .NET中基于DOM核心类 XmlDocument 表示一个XML文档 XmlNode表示X ...

  5. 自学Zabbix3.3-一个简单例子 添加Hosts并应用模板

    Host 是 Zabbix 监控的基本载体,所有的监控项都是基于 host 的. 通过 Configuration->Hosts->Create Host 来创建监控设备 按提示填入 Na ...

  6. mybatis generator为实体类生成自定义注释(读取数据库字段的注释添加到实体类,不修改源码)

    我们都知道mybatis generator自动生成的注释没什么实际作用,而且还增加了代码量.如果能将注释从数据库中捞取到,不仅能很大程度上增加代码的可读性,而且减少了后期手动加注释的工作量. 1.首 ...

  7. EF简单的添加修改删除基本语法

    using ( androidhiveEntities db = new androidhiveEntities() )                {                    #re ...

  8. 百度地图简单使用——添加折线,圆形等(html,js)

    地图覆盖物概述 所有叠加或覆盖到地图的内容,我们统称为地图覆盖物.如标注.矢量图形元素(包括:折线和多边形和圆).信息窗口等.覆盖物拥有自己的地理坐标,当您拖动或缩放地图时,它们会相应的移动. 地图A ...

  9. eclipse简单注释规范

    设置注释模板的入口: Window->Preference->Java->Code Style->Code Template Types/*** @ClassName: ${t ...

随机推荐

  1. Arcgis api for javascript学习笔记(4.5版本)-三维地图的飞行效果

    其实就只是用到了 view.goTo()  函数,再利用 window.setInterval()  函数(定时器)定时执行goTo().代码如下: <!DOCTYPE html> < ...

  2. android隐藏显示小键盘

    记录一下开发中虚拟键盘的使用,fragment和activity中不同的使用 fragment下点击其它位置隐藏小键盘,复制到initView()方法中 view.setOnTouchListener ...

  3. phpstudy2018升级MySQL5.5为5.7.24教程(图文)

    原文: phpstudy2018升级MySQL5.5为5.7教程(图文) 一.MySQL官网下载MySQL5.7版本,我这里下载的是MySQL5.7.24. 二.直接到D:phpStudyPHPTut ...

  4. 各个版本 Windows 10 系统中自带的 .NET Framework 版本

    原文各个版本 Windows 10 系统中自带的 .NET Framework 版本 Windows 名称 Windows 版本 自带的 .NET Framework 版本 Windows 10 Oc ...

  5. Python 内置函数 —— format

    科学计数法: >> format(2**20, '.2e') '1.05e+06' 小数 ⇒ 百分数 >> format(.1234, '.1%') 12.3%

  6. WPF: Creation of Text Labels for 3D Scene

    原文:WPF: Creation of Text Labels for 3D Scene 转载:http://www.codeproject.com/KB/WPF/WPF_Text3D.aspx Do ...

  7. matlab 工具函数 —— normalize(归一化数据)

    function x = normalize(x, mu, sigma) x = bsxfun(@minus, x, mu); x = bsxfun(@rdivide, x, sigma); end ...

  8. 一款天气app的温度曲线图的实现

    原文:一款天气app的温度曲线图的实现 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/tyhzsd/article/details/50544639 ...

  9. 经典c开源项目

    1. Webbench Webbench是一个在Linux下使用的非常简单的网站压测工具.它使用fork()模拟多个客户端同时访问我们设定的URL,测试网站在压力下工作的性能,最多可以模拟3万个并发连 ...

  10. XF 列表视图事件

    <?xml version="1.0" encoding="utf-8" ?><ContentPage xmlns="http:// ...