Question

Noticed a strange thing today. I have some code like this in a project I'm working on:

var directoryEntry =new DirectoryEntry(
    ConfigurationManager.AppSettings["path"],
    ConfigurationManager.AppSettings["user"], 
    ConfigurationManager.AppSettings["password"]
);

This is part of a class library. When I used this library from another project, I forgot to define those keys in the .config file for the application/site, yet it still worked.

My suspicion is that this constructor works similarly to the PrincipalContext constructor http://msdn.microsoft.com/en-us/library/bb298328.aspx, in that it uses the current user's credentials if you pass nulls, although the MSDN documentation doesn't say anything about it.

Can anyone confirm or deny this?

Was it helpful?

Solution

This code sample is not throwing an exception but that doesn't mean it's necessarily working. The DirectoryEntry constructor doesn't do any type of authentication or validation of the values that are passed to it. Instead it merely stores these values which it will later attempt to use in order to make a query on the server.

This particular code won't throw or fail with empty strings but any call on it which causes it to bind to the server will very likely fail.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top