When Iam creating a new account, then it will add the groups to the users successfully. But when I enable the disabled account and then trying to add the groups, then only it creates the problem like The server is unwilling to process the request or
Exception has been thrown by the target of an invocation....
anandh_aspdo...
Member
4 Points
27 Posts
The server is unwilling to process the request.
Apr 03, 2012 08:59 AM|LINK
Hi,
Im trying to add the groups to the user. But it gives error while commitchanges:
The server is unwilling to process the request.
Please find the code below.
for(int x = 0; x < arrGroup.Length; x++)
{
DirectoryEntry FilterEntry = new DirectoryEntry(LDAP://Corp.Suth.com/DC=Corp,DC=Suth,DC=com);
DirectorySearcher Search = new DirectorySearcher(FilterEntry);
Search.Filter =string.Format("(&(objectclass=group)(CN=" + arrGroup[x] + "))");
Search.PropertiesToLoad.Add("adspath");
SearchResultCollection resultcol = Search.FindAll();
if(resultcol.Count > 0)
{
foreach (SearchResult sr in resultcol)
{
foreach (string PropertyName in sr.Properties.PropertyNames)
{
foreach (object retentry in sr.Properties[PropertyName])
{
string GroupDN;
GroupDN = null;
GroupDN ="" + retentry.ToString() + "";
DirectoryEntry de = new DirectoryEntry(GroupDN);
de.Properties["Member"].Add(UserCN);
de.CommitChanges();
twGroup.WriteLine("Assigned as member to the group " + " -- "+ arrGroup[x]);
de.Close();
}
}
}
}
else
twGroup.WriteLine("Group " + " -- " + arrGroup[x] + " -- " + " not found");
}
DarrellNorto...
All-Star
87473 Points
9723 Posts
Moderator
MVP
Re: The server is unwilling to process the request.
Apr 03, 2012 09:19 AM|LINK
Instead of this:
de.Properties["Member"].Add(UserCN);
de.CommitChanges();
Try this:
de.Invoke("Add", New Object() {UserCN})
Darrell Norton's Blog
Please click "Mark as Answer" if this helped you.
anandh_aspdo...
Member
4 Points
27 Posts
Re: The server is unwilling to process the request.
Apr 03, 2012 10:46 AM|LINK
I have did as u said, but im getting another exception
Exception has been thrown by the target of an invocation.
anandh_aspdo...
Member
4 Points
27 Posts
Re: The server is unwilling to process the request.
Apr 03, 2012 02:38 PM|LINK
When Iam creating a new account, then it will add the groups to the users successfully. But when I enable the disabled account and then trying to add the groups, then only it creates the problem like The server is unwilling to process the request or Exception has been thrown by the target of an invocation....
Can u pls help me in this regard....