UserPrincipal Object, Active Directory Query: DirectoryServicesCOMException

2

Apologies for duplicate of System.DirectoryServices.DirectoryServicesCOMException: An operations error occurred but I can't comment yet and there's no answer.

The solution from this question, did not work. Error on publishing: System.DirectoryServices.DirectoryServicesCOMException

I've got a new ASP.NET MVC 3 web application project with Razor view engine in Visual Studio 2010. It is as generated with the addition of two lines of code added to the home controller and the System.DirectoryServices.AccountManagement reference added to the project.

This runs just fine on my local PC, but I get an error on a Windows 2008 R2 IIS 7.5 site I've created.

The site uses the defaultAppPool, which is using ApplicationPoolIdentity. The root site folder has been granted IUSR and IIS AppPool\DefaultAppPool read permissions.

The two lines of code in the controller are:

PrincipalContext context = new PrincipalContext(ContextType.Domain);
ViewBag.name = UserPrincipal.FindByIdentity(context, User.Identity.Name).DisplayName;

The error I get is:

System.DirectoryServices.DirectoryServicesCOMException: An operations error occurred.

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() +535649
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, Nullable1 identityType, String identityValue, DateTime refDate) +27
System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(PrincipalContext context, String identityValue) +95
ActiveDirectory.Controllers.HomeController.Index() in C:\projects\ActiveDirectory\ActiveDirectory\Controllers\HomeController.cs:18
lambda_method(Closure , ControllerBase , Object[] ) +79
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary
2 parameters) +248
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) +39
System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +125
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func
1 continuation) +640
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList1 filters, ActionDescriptor actionDescriptor, IDictionary2 parameters) +312
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +691
System.Web.Mvc.Controller.ExecuteCore() +162
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +305
System.Web.Mvc.<>c__DisplayClassb.b__5() +62
System.Web.Mvc.Async.<>c__DisplayClass1.b__0() +20
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +469
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +375

Be nice, it's my first question!

c#
asp.net
asked on Stack Overflow Jan 15, 2013 by Ryan Stewart • edited May 23, 2017 by Community

1 Answer

4

Most likely this is a permissions issue. Check that the account the App Pool is running under has the authority to perform these Active Directory calls. If it's a local machine account, it probably won't.

You can find more information here: http://msdn.microsoft.com/en-US/library/ms180891(v=vs.80).aspx

answered on Stack Overflow Jan 15, 2013 by Pete

User contributions licensed under CC BY-SA 3.0