当前位置: 首页 > news >正文

徐州云龙城乡建设局网站高校人力资源管理系统网站开发

徐州云龙城乡建设局网站,高校人力资源管理系统网站开发,广州市网站建设公司在哪里,广告营销策划案在之前的文章《dotNET Core 中怎样操作 AD#xff1f;》中主要以AD的数据同步到数据库的场景来描述了在 dotNetCore 中怎样操作AD#xff0c;本文将继续介绍一些在 dotNetCore 中操作 AD 的其他常用操作。环境dotNET Core#xff1a;3.0Novell.Directory.Ldap.NETStandard2_… 在之前的文章《dotNET Core 中怎样操作 AD》中主要以AD的数据同步到数据库的场景来描述了在 dotNetCore 中怎样操作AD本文将继续介绍一些在 dotNetCore 中操作 AD 的其他常用操作。环境dotNET Core3.0Novell.Directory.Ldap.NETStandard2_03.1.0ADwindows server 2012基本操作查询在 AD 中进行用户的操作通常需要先判断用户是否存在这时就需要使用查询了用下面代码可以进行 AD 中的查询 var entities  _connection.Search(ADClient.BaseDC,LdapConnection.SCOPE_SUB,$sAMAccountName{loginName},null, false); 参数说明base: 指定的总体搜索范围通常在创建连接时会指定一个 BaseDC表示后面的操作在此 DC 范围内,如果希望从根开始搜索此参数可传空scope查询遍历的方式分为 SCOPE_BASE 、SCOPE_ONE 和 SCOPE_SUB 三种SCOPE_BASE通常知道对象的 DN并希望获取其属性时使用此项SCOPE_ONE查询 base 的下一层级SCOPE_SUB查询 base 下的所有对象包含 basefilter用来过滤的表达式下面列出一些常用的表达式(cnoec2003)返回 cn 等于 oec2003 的用户 (sAMAccountNameoec*)返回登录名以 oec 开头的用户 !(cnoec2003)返回 cn 不等于 oec2003 的用户 (|(cnoec2003)(telephonenumber888*))返回 cn 等于 oec2003 或者电话号码以 888 开头的用户 ((cnoec2003)(telephonenumber888*))返回 cn 等于 oec2003 并且电话号码以 888 开头的用户 其他更多的表达式可以参考官方文档https://www.novell.com/documentation/developer/ldapcsharp/?page/documentation/developer/ldapcsharp/cnet/data/bovtuda.htmlattrs字符串数组可以指定返回的属性的列表不指定返回所有的属性例如根据登录名来查询用户的示例代码如下public static LdapEntry GetUser(string loginName) {var entities  _connection.Search(ADClient.BaseDC,LdapConnection.SCOPE_SUB,$sAMAccountName{loginName},null, false);LdapEntry entry  null;while (entities.HasMore()){try{entry  entities.Next();}catch (LdapException e){Console.WriteLine($GetUser Error: {e.Message});continue;}}return entry; } 添加用户public static bool AddUser(string userName, string loginName, string defaultPwd, string container) {//设置默认密码defaultPwd  $\{defaultPwd}\;sbyte[] encodedBytes  SupportClass.ToSByteArray(Encoding.Unicode.GetBytes(defaultPwd));LdapAttributeSet attributeSet  new LdapAttributeSet();attributeSet.Add(new LdapAttribute(objectclass, user));attributeSet.Add(new LdapAttribute(sAMAccountName, userName));//设置创建用户后启用attributeSet.Add(new LdapAttribute(userAccountControl, (66080).ToString()));attributeSet.Add(new LdapAttribute(unicodePwd, encodedBytes));string dn  $CN{loginName},{container};LdapEntry newEntry  new LdapEntry(dn, attributeSet);_connection.Add(newEntry);return true; } 注意点默认密码的设置需要给密码加上引号默认情况下创建的用户是禁用的如果要启用需要加上代码attributeSet.Add(new LdapAttribute(userAccountControl, (66080).ToString()));修改密码public static bool UpdatePassword(string loginName, string password) {LdapEntry entry  GetUser(loginName);if (entry  null){throw new Exception($名为:{loginName} 的用户在AD中不存在);}password  $\{password}\;sbyte[] encodedBytes  SupportClass.ToSByteArray(Encoding.Unicode.GetBytes(password));LdapAttribute attributePassword  new LdapAttribute(unicodePwd, encodedBytes);_connection.Modify(entry.DN, new LdapModification(LdapModification.REPLACE, attributePassword));return true; } 禁用用户public static bool EnblaedUser(string loginName) {LdapEntry entry  GetUser(loginName);if (entry  null){throw new Exception($名为:{loginName} 的用户在AD中不存在);}LdapAttribute attributePassword  new LdapAttribute(userAccountControl, (66082).ToString());_connection.Modify(entry.DN, new LdapModification(LdapModification.REPLACE, attributePassword));return true; } 启用用户public static bool EnblaedUser(string loginName) {LdapEntry entry  GetUser(loginName);if (entry  null){throw new Exception($名为:{loginName} 的用户在AD中不存在);}LdapAttribute attributePassword  new LdapAttribute(userAccountControl, (66080).ToString());_connection.Modify(entry.DN, new LdapModification(LdapModification.REPLACE, attributePassword));return true; } 移动用户到新的 OUpublic static bool MoveUserToOU(string loginName, string rcn  , string ouContainer  ) {LdapEntry entry  GetUser(loginName);if (entry  null){throw new Exception($名为:{loginName} 的用户在AD中不存在);}string cn  entry.AttrStringValue(cn);cn  rcn   ? cn : rcn;string newRCN  $CN{cn};if (string.IsNullOrWhiteSpace(ouContainer)){_connection.Rename(entry.DN, newRCN, true);}else{_connection.Rename(entry.DN, newRCN, ouContainer, true);}return true; } 注意点一个用户一旦创建DN 是不能修改的可以通过Rename方法来修改 CN 来达到修改 DN 的目的如果传入第三个参数ouContainer,就可以实现将用户移动到目标 OU添加用户到组public static bool AddUserToGroup(string loginName, string groupDN) {LdapEntry entry  GetUser(loginName);if (entry  null){throw new Exception($名为:{loginName} 的用户在AD中不存在);}Liststring memberOf  entry.AttrStringValueArray(memberOf);if (memberOf.Contains(groupDN)){throw new Exception($名为:{loginName} 的用户已经加入了组: {groupDN});}LdapModification[] modGroup  new LdapModification[1];LdapAttribute member  new LdapAttribute(member, entry.DN);modGroup[0]  new LdapModification(LdapModification.ADD, member);try{_connection.Modify(groupDN, modGroup);}catch (LdapException e){System.Console.Error.WriteLine(Failed to modify groups attributes:   e.LdapErrorMessage);return false;}catch (Exception e){Console.Error.WriteLine(AddUserToGroup Error:  e.Message);return false;}return true; } 用户从组中移除public static bool RemoveUserFromGroup(string loginName, string groupDN) {LdapEntry entry  GetUser(loginName);if (entry  null){throw new Exception($名为:{loginName} 的用户在AD中不存在);}Liststring memberOf  entry.AttrStringValueArray(memberOf);if (!memberOf.Contains(groupDN)){throw new Exception($名为:{loginName} 的用户不存在于组: {groupDN} 中);}LdapModification[] modGroup  new LdapModification[1];LdapAttribute member  new LdapAttribute(member, entry.DN);modGroup[0]  new LdapModification(LdapModification.DELETE, member);try{_connection.Modify(groupDN, modGroup);}catch (LdapException e){System.Console.Error.WriteLine(Failed to delete groups attributes:   e.LdapErrorMessage);return false;}catch (Exception e){Console.Error.WriteLine(RemoveUserFromGroup Error:  e.Message);return false;}return true; } 添加用户登录到public static bool UpdateUserWorkStation(string loginName, string computerName, UserWorkStationOperType type) {LdapEntry entry  GetUser(loginName);if (entry  null){throw new Exception($名为:{loginName} 的用户在AD中不存在);}Liststring stations  entry.AttrStringValue(userWorkstations).Split(,).ToList();if (type  UserWorkStationOperType.Add  !stations.Contains(computerName)){stations.Add(computerName);}else if (type  UserWorkStationOperType.Remove  stations.Contains(computerName)){stations.Remove(computerName);}LdapAttribute attributePassword  new LdapAttribute(userWorkstations, string.Join(,, stations));_connection.Modify(entry.DN, new LdapModification(LdapModification.REPLACE, attributePassword));return true; } 最后本文的示例代码已推送到 GitHubhttps://github.com/oec2003/DotNetCoreAdDemo官网也有些示例但不是很完善而且有很多代码并不能正常执行可能跟 AD 的版本有关所以才有了本示例。本示例也会添加更多的使用场景不断完善。希望本文对您有所帮助。
http://www.ihoyoo.com/news/12215.html

相关文章:

  • 长尾关键词搜索网站在线做漫画的网站
  • 郑州网站优化公司电话做的比较好的时尚网站
  • seo网站优化专员手机型号最全的网站
  • dede网站搬家教程网站建设论文总结
  • 做网站必须开厂吗网页广告关不掉怎么办
  • 做网站大概要多太原网站建设最好
  • 上海opencart网站建设电子网络工程建设范围
  • 临沂做wish网站网站 备案规定
  • 网站搭建与服务器配置深圳政务服务网官网首页
  • jsp网站开发工具及语言会员管理软件
  • 网站设计企举例说明商业网站的建设流程
  • 镇江专业建网站中牟建设局网站
  • 集团网站设计案例大型电子商务网站开发架构
  • 做网站的软件叫code公司网站建设模板免费
  • 动漫网站源码下载襄阳做网站 优帮云
  • 建设银行网站注册运营管理系统
  • 网站 建设 现状分析个人网站备案电话访谈
  • 在线教育网站建设餐厅vi设计公司
  • 百度收录哪个网站多网站关键字被改了
  • 局域网视频网站建设wordpress首页怎么进入
  • 广州城市职业学院门户网站浙江省住房和城乡建设信息网
  • 营销型网站建设怎么收费温州网站建设新手
  • 最便宜 双网站建设纯php网站开发的网站
  • 华容县住房和城乡建设局网站怎样在网站是做宣传
  • 建网站的公司哪家好高端建站平台设计风格出众
  • 做门户网站最重要的是什么意思设计公司企业介绍
  • 网站建站发布平台市场营销策划是干嘛的
  • 东莞网站建设 包装材料seo资料网
  • 工信部信息备案网站查询系统怎么用群晖nas做网站
  • 自己做免费网站网站建设利润越来越低