I am having trouble adding a user to AD with the following code:
public static DirectoryEntry CreateNewUser(string samAccountName)
{
//set the LDAP qualification so that the user will be created under the
Users
//container.
// GetLDAPDomain will read in the ADServer value from the web.config and
will return it
// as an LDAP path eg DC=SVR1, DC=HEADOFFICE, DC=NET.
string LDAPDomain ="/CN=Users," + GetLDAPDomain() ;
DirectoryEntry oDE= GetDirectoryObject(LDAPDomain);
DirectoryEntry oDEC=oDE.Children.Add("CN=Testuser","User");
oDE.Close();
return oDEC;
}
private static DirectoryEntry GetDirectoryObject()
{
//please note ADUser & Pass are Domain Administrator details
currently DirectoryEntry oDE;
oDE = new
DirectoryEntry(ADPath,ADUser,ADPassword,AuthenticationTypes.Secure);
return oDE;
}
GetDirectoryObject appears OK as i use it to perform a directorysearch
which
works well. When running the above code the following line throws the
following exception:
line in question:
DirectoryEntry oDEC=oDE.Children.Add("CN=Testuser","User");
Exception info:
[COMException (0x80005000): Unknown error (0x80005000)]
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
System.DirectoryServices.DirectoryEntry.Bind()
System.DirectoryServices.DirectoryEntry.get_IsContainer()
System.DirectoryServices.DirectoryEntries.CheckIsContainer()
System.DirectoryServices.DirectoryEntries.Add(String name, String
schemaClassName)
Dev/Testing Environment is as follows:
Single Machine IIS Server AND Domain Controller
Windows 2003 STD SPK2
VIS Studio 2003
..NET 1.1
Application using Basic Authentication (this is a must)
App Pool Identity=network service
I have tried running the code impersonating the administrator details.
Any help is much appreciated


|