Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

2 Answers 2

You can retrieve users as follows:

SPWeb.EnsureUser("providername:username");

so suppose your provider is called ContosoMembership and your user is user@web.com, the call would be:

SPWeb.EnsureUser("ContosoMembership:user@web.com");

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

 
discard

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.