Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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);
            /* Impersonate the user */
            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 + ")";
                // deSearch.SearchScope = SearchScope.Subtree;
                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.
Posted
Updated 22-Mar-10 22:20pm
v2

1 solution

Have you tried serverless binding?
Instead of:
silentdeepa wrote:
LDAP://FullyQualifiedServerName/OU=Users, OU=NPP,DC=example,DC=myserver,DC=in


Use:
LDAP://domain.com/DC=domain,DC=com,OU=Users,OU=NPP,DC=example,DC=myserver,DC=in

(you may also need to put<identity impersonate="true" /> in the web.config.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900