在AD密码修改操作时报错:System.Runtime.InteropServices.COMException: The server is not operational 该服务器不可操作!...

本文介绍了一段用于修改Active Directory (AD) 用户密码的C#代码,并详细记录了在不同环境中运行时遇到的问题及解决方案。问题在于本地DNS未正确配置指向AD服务器,导致无法成功修改密码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

None.gif using  System.DirectoryServices;
None.gif
None.gif
try
ExpandedBlockStart.gifContractedBlock.gif            
dot.gif {
InBlock.gif
InBlock.gif                
string sAMAccountName = "xingtingting";
InBlock.gif                
string newPassword = "12345678";
InBlock.gif                
//iw.local/OU=HXZ,
InBlock.gif
                DirectoryEntry de = new DirectoryEntry("LDAP://iw.local/OU=HXZ,DC=iw,DC=local","iw\\spsadmin","iswind",AuthenticationTypes.Sealing );
InBlock.gif                DirectorySearcher deSearch 
= new DirectorySearcher(de);
InBlock.gif                deSearch.Filter    
= "(&(&(objectCategory=person)(objectClass=user))(sAMAccountName=" + sAMAccountName    + "))";
InBlock.gif                deSearch.SearchScope 
= SearchScope.Subtree;
InBlock.gif                SearchResult result    
= deSearch.FindOne();
InBlock.gif                de 
= new DirectoryEntry(result.Path);
ExpandedSubBlockStart.gifContractedSubBlock.gif                de.Invoke(
"SetPassword"new object[]dot.gif{newPassword});
InBlock.gif                de.CommitChanges();
InBlock.gif                de.Close();
InBlock.gif
InBlock.gif                System.Windows.Forms.MessageBox.Show(
"修改成功!");
InBlock.gif
ExpandedBlockEnd.gif            }

None.gif            
catch  (Exception ex)
ExpandedBlockStart.gifContractedBlock.gif            
dot.gif {
InBlock.gif                
throw ex;
ExpandedBlockEnd.gif            }
执行至: de.Invoke("SetPassword",new object []{newPassword});抛异常。
在AD服务器上运行正常,但在加入域的服务器运行就出错。可以断定应该不是程序的问题,但找了很久也没找到解决办法。后来在http://www.highdots.com/forums/asp-net-security/change-password-active-directory-webapplication-700434.html看到一段话:
You may need to experiment with different variations on the dcDNS variable
and you may need to remove the ServerBind flag if you are using a NETBIOS
name. Also, you may need to remove the Sealing flag as well, but be warned
that in order to set or change passwords, some sort of encrypted channel
(SSL or Kerberos) must be available.
突然想到犯了一个低级错误!没有把DNS设置正确!!因为测试AD服务器也是DNS服务器,所以需要把AD服务器的地址配到本机的DNS中。配置后运行成功!

转载于:https://www.cnblogs.com/muskteer/archive/2006/01/07/312800.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值