Martin Hinshelwood's Blog

A Scottish dyslexic software developer: .NET architect, developer, evangelist, technology enthusiast and multi-dimensional free thinker


News

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Subscribe

Personal

Accreditation

Stats

My Stats

  • Posts - 264
  • Comments - 305
  • Trackbacks - 67

Twitter












Tag Cloud


Recent Comments


Recent Posts


Article Categories


Archives


Post Categories


Image Galleries


Blogs I read


Blogs of Friends


Blogs on VSTS


Multi-Dimentional Free Thinking Bloggers


Personal


Projects



I have found a small bug (as in, "Not working as expected!") in the new .NET 3.5 PrincipalContext classes. When you are running on an ASP.NET site in impersonation mode you cannot retrieve information from active directory without the following error:

System.Runtime.InteropServices.COMException (0x80072020): An operations error occurred. at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) at System.DirectoryServices.DirectoryEntry.Bind() at System.DirectoryServices.DirectoryEntry.get_AdsObject() at System.DirectoryServices.PropertyValueCollection.PopulateList() at System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName) at System.DirectoryServices.PropertyCollection.get_Item(String propertyName) at System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInitNoContainer() at System.DirectoryServices.AccountManagement.PrincipalContext.DoDomainInit() at System.DirectoryServices.AccountManagement.PrincipalContext.Initialize() at System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx() at System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext context, Type principalType, Nullable`1 identityType, String identityValue, DateTime refDate) at System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithType(PrincipalContext context, Type principalType, IdentityType identityType, String identityValue) at System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(PrincipalContext context, IdentityType identityType, String identityValue) at UI_Controls_SharepointControl.Page_Load(Object sender, EventArgs e)

You need to specify a fixed account to access AD using:

Dim ctx As New PrincipalContext(ContextType.Domain, "[domain]", "[accountName]", "[password]")

This is not so good! What if I wanted to use the current users credentials to update only fields that they are allowed to update in AD? If I use a static account that can access any users fields then this becomes a security risk.

Ahh well, I will live with it for now, but if anyone has another suggestion...

 


posted @ Tuesday, March 04, 2008 10:18 AM | Filed Under [ Microsoft .NET Framework Microsoft Windows WCF ]

Comments

Gravatar # re: What the 0x80072020?
Posted by kyt.sarasota on 3/25/2008 5:10 PM
bugs. Everywhere theres bug. Vista still sucks. Worst than anything else when it comes to OS.
Gravatar # re: What the 0x80072020?
Posted by marc on 4/1/2008 4:55 PM
I'm getting the same error in a MOSS 2007 context...

Gravatar # re: What the 0x80072020?
Posted by David Steadman on 4/7/2008 4:13 AM
I am getting the same error if I deploy my webpart to an external site.. works fine if the site is using internal site ie http://server01/
not www.site.com.. something to do with the connected server under the context.. any solution would be great if you have found a fix..
Gravatar # re: What the 0x80072020?
Posted by bipbip on 4/23/2008 12:54 AM
"bugs. Everywhere theres bug. Vista still sucks. Worst than anything else when it comes to OS. "

yea. and 95 was terrible compared to 3.1 because some things just didnt work right.

Gravatar # re: What the 0x80072020?
Posted by Martin Hinshelwood on 4/23/2008 10:05 AM
And XP was rubbish compaired to 98 coz it used more memory and some of your application did not work...
Gravatar # re: What the 0x80072020?
Posted by Turkey on 7/31/2008 7:03 AM
Thanx You.. Perfect Docs

Gravatar # re: What the 0x80072020?
Posted by pete w on 8/6/2008 8:12 PM
I used the following code:

PrincipalContext principalContext = new PrincipalContext(ContextType.Domain, Environment.UserDomainName)

then the principalcontext will take on the identity of the application environment. In the case f a web application, that will be the identity of the web application's pool's identity. I dont know if that is any more useful to you, but thanks for getting me started in the right direction!
Post a comment





 

Please add 4 and 7 and type the answer here: