Mittwoch, 26. Juni 2013

Can't access the Active Directory

I had a problem on a server to access the Active Directory. The error-message led to the following method:

Server stack trace: at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) at System.DirectoryServices.DirectoryEntry.Bind()

When debugging, I got the error that the Context was null.

What saved my day was to wrap the whole Active Directory performance into an impersonation.

using(HostingEnvironment.Impersonate())
{
My active directory code
}