I have looked at every posting regarding the reasons for the following exception:
An unhandled exception has occurred. at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) at System.DirectoryServices.DirectoryEntry.Bind() at System.DirectoryServices.DirectoryEntry.get_AdsObject() at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne) at System.DirectoryServices.DirectorySearcher.FindOne()
It appears that the best solution for this issue is to use HostingEnvironment.Impersonate() when calling DirectorySearcher as suggested in many links including the ones below: Active Directory COM Exception - An operations error occurred (0x80072020) and Getting Error Querying Active Directory On The Server Only I encapsulated my code for accessing DirectorySearcher in using (HostingEnvironment.Impersonate()) as suggested and it stopped getting the exception but it cannot find the user. The only way I have seen it get further is to make in my web.config file but even that is not fetching the correct user, which is supposed to be the windows user. Do I need to change anything in the IIS configuration? I should mention that similar to other posts related to this subject, this code works fine in my local environment, i.e. running from VStudio on its own IIS server. I only get this when I deployed the app and attempted to run from another IIS server. Any help will be greatly appreciated. Thanks.
Double check your LDAP path.
Regarding the COM Exception, I switched from "AppPoolIdentity" to "NetworkService", which solved my issue.
User contributions licensed under CC BY-SA 3.0