SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
Can any one help on this ? – Monica Jagani Oct 4 '11 at 5:49
any idea on this? – Monica Jagani Oct 11 '11 at 6:16

You can retrieve users as follows:


so suppose your provider is called ContosoMembership and your user is, the call would be:


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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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