AccountManagement.UserPrincipal.Current takes 5 seconds

I'm using the new .NET 3.5 System.DirectoryServices.AccountManagement API.

In my code, I need to determine the current System.DirectoryServices.AccountManagement.UserPrincipal.

My naive approach was to do this:

using AccountManagement = System.DirectoryServices.AccountManagement;

...

// Determine current UserPrincipal.
// (On my machine, this blocks for 5 seconds)
//

AccountManagement.UserPrincipal principal = AccountManagement.UserPrincipal.Current;

My computer is a stand-alone machine running Vista. I am not part of any domain, etc.

Any ideas on how to improve the performance?

Answers


My guess is that since DirectoryServices is geared towards looking up data in a directory, in this case Active Directory, and you are on a single machine, it times out with the request to find a Domain Controller.

I assume you want to get the name of the current user, and you can do that by using the "old" System.Security.Principal.WindowsIdentity.GetCurrent() method instead.

If you need the principal for that user, you can use this code:

WindowsIdentity ident = WindowsIdentity.GetCurrent();
IPrincipal principal = new WindowsPrincipal(ident);

Need Your Help

If I come from an imperative programming background, how do I wrap my head around the idea of no dynamic variables to keep track of things in Haskell?

variables haskell imperative

So I'm trying to teach myself Haskell. I am currently on the 11th chapter of Learn You a Haskell for Great Good and am doing the 99 Haskell Problems as well as the Project Euler Problems.

Multiple call PreDestroy method by omnifaces ViewScoped

java jsf primefaces omnifaces

Invoke PostConstruct method at Initial requests. But, when I upload the images, there are multiple call PreDestroy method.