问题描述
我使用了 this page 将用户添加到 Active Directory 组,但我在执行时收到一条异常消息服务器不愿意处理请求"
I used the example in this page to add a user to an Active Directory group, but I get an exception with the message "Server is unwilling to process the request" when executing
dirEntry.Properties["member"].Add(userDn);
推荐答案
这个问题花了我很多时间才解决.首先,错误信息看起来像一个笑话.其次,没有别的了,只有那个消息.
This question took me a lot of time to solve. First of all, the error message looks like a joke. Second, there is nothing more, just that message.
无论如何,我设法通过以下方式修复它:
Anyway, I managed to fix it by:
确保
userDn
包含整个路径(例如,"LDAP://server-address/CN=" + userDn + ",OU=optional,DC=your-domain,DC=com"
.这实际上非常重要,如果您不提供完整路径,它将抛出一个HRESULT 异常:0x80005000>.
Making sure that
userDn
contains the whole path (e.g.,"LDAP://server-address/CN=" + userDn + ",OU=optional,DC=your-domain,DC=com"
. This is actually very important, if you don't supply the full path it will throw an Exception from HRESULT: 0x80005000.
替换 dirEntry.Properties["member"].Add(userDn);
由 entry.Invoke("Add", new object[] { userDn });
然后我想删除一个用户,我希望 entry.Invoke("Remove", new object[] { userDn });
工作.然而,这个邪恶的广告只有在你使用小写remove"时才有效,所以 entry.Invoke("remove", new object[] { userDn });
有效对我来说.
Then I wanted to remove a user and I expected entry.Invoke("Remove", new object[] { userDn });
to work. However, this devilish AD will only work if you use lower case "remove", so entry.Invoke("remove", new object[] { userDn });
worked for me.
这篇关于服务器不愿意处理请求 - Active Directory - 通过 C# 添加用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!