Hi,
I need to access Active Directory that resides on Windows 2003 server from an ASPX application that is hosted on another Windows 2003 server.
I code works fine if both the Active Directory and ASPX application are on same server. But I get "The server is not operational" error when the servers are different.
The LDAP path I use is LDAP://FullyQualifiedServerName/OU=Users, OU=NPP,DC=example,DC=myserver,DC=in. (This works if both the Active Directory and ASPX application are hosted on the same server).
I have established two-way trust between the two windows 2003 domains by going to "Active Directory Domains And Trust" and adding the domain to Trust tab. I used trust type as Realm since "Trust with a Windows domain" did not work. This I did on both the server machines. I have disabled the Guest user account and I have same the user ( and same password) in both the servers. I have impersonated this user when I access active directory.
This is my code:
HttpContext context = HttpContext.Current;
IServiceProvider iServiceProvider = context as IServiceProvider;
Type httpWorkerRequestType = typeof(HttpWorkerRequest);
HttpWorkerRequest httpWorkerRequest =
iServiceProvider.GetService(httpWorkerRequestType) as HttpWorkerRequest;
IntPtr ptrUserToken = httpWorkerRequest.GetUserToken();
WindowsIdentity winIdentity = new WindowsIdentity(ptrUserToken);
WindowsImpersonationContext impContext = winIdentity.Impersonate();
...
DirectoryEntry de = new DirectoryEntry(path, admin, apwd, AuthenticationTypes.Secure);
DirectorySearcher deSearch = new DirectorySearcher();
deSearch.SearchRoot = de;
deSearch.PropertiesToLoad.Add("distinguishedName");
deSearch.PropertiesToLoad.Add("samAccountName");
deSearch.Filter = "(samAccountName=" + UserName + ")";
SearchResult results = deSearch.FindOne();
if (!(results == null))
ds = results.Properties["distinguishedName"][0].ToString();
}
catch (Exception e)
{
throw e;
}
When I get to FindOne() it throws an Exception-"The server is not operational" The stack trace indicates error at DirectoryEntry.Bind() method.
Could any one tell me where I am going wrong. Incase there are other ways to get this working I am open to that too. But architecture is Active Directory is on a different server from IIS web server where the application is hosted.
Thanks in advance,
Deepa
Thanks in advance.