Can't access directory services from server - DirectoryServicesCOMException

1

I'm trying to query AD in an ASP.Net (4.0) application that is running on Windows Server 2008 R2 (IIS7 installed). In runs fine on my local computer (Windows 7), but not on the server. I'm trying to get the userid of the current user. I've looked at Q&A of similar question, but no success.

Here's the code snip...

public partial class Default : System.Web.UI.Page
    {
        PrincipalContext principalCtx = new PrincipalContext(ContextType.Domain);
        UserPrincipal currentUser = UserPrincipal.Current;

The web.config has

<authentication mode="Windows"/>
<identity impersonate="true" />

And here's the error & stack trace...

[DirectoryServicesCOMException (0x80072020): An operations error occurred.
]
   System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) +781
   System.DirectoryServices.DirectoryEntry.Bind() +44
   System.DirectoryServices.DirectoryEntry.get_AdsObject() +42
   System.DirectoryServices.PropertyValueCollection.PopulateList() +29
   System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName) +119
   System.DirectoryServices.PropertyCollection.get_Item(String propertyName) +163
   System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInitNoContainer() +541617
   System.DirectoryServices.AccountManagement.PrincipalContext.DoDomainInit() +51
   System.DirectoryServices.AccountManagement.PrincipalContext.Initialize() +141
   System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx() +42
   System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext context, Type principalType, Nullable`1 identityType, String identityValue, DateTime refDate) +27
   System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithType(PrincipalContext context, Type principalType, IdentityType identityType, String identityValue) +146
   System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(PrincipalContext context, IdentityType identityType, String identityValue) +44
   System.DirectoryServices.AccountManagement.UserPrincipal.get_Current() +390

I've tried running IIS Application Pool as NetworkService and as ApplicationPoolIdentity and no good.

Any ideas? Thanks.

c#
asp.net
directoryservices
asked on Stack Overflow May 4, 2013 by mpavitt

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0