I have 3 security provider for my web application 1. Active Directory 2. ADFS 3. SAML

Now suppose a user exist in all 3 provider.Hence when i do use ensure user method i get error/ exception "user not found". I want that my code should always get the user from active directory and if not found through user not found error.

Can anyone provide me with code snippet.

  • Can any one help on this ? Commented Oct 4, 2011 at 5:49
  • any idea on this? Commented Oct 11, 2011 at 6:16

2 Answers 2


You can retrieve users as follows:


so suppose your provider is called ContosoMembership and your user is [email protected], the call would be:

SPWeb.EnsureUser("ContosoMembership:[email protected]");

But there's one catch. You have to configure your providers in the context your running your app in. So if this is a console application for instance; make sure the app.config of your console app also holds the proper membership providers! If the providers aren't configured, you will get an error saying the user can't be found. When running in SharePoint context (webpart, application page), it uses the web.config you've configured so you're safe there.


try SPUtility.ResolvePrincipal

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.