1

I have a requirement where I am checking a user account whether it does exist in User Profile Service or not. And if the account doesn't exist then it will create an account. I am using CSOM for this.

It throws an exception "Forbidden" on clientContext.ExecuteQuery() when I don't impersonate the identity and the account doesn't exist. By impersonating the identity the account gets created even for those user whose accounts are already existent which I don't prefer. I am using the following code:

var loginName = HttpContext.Current.User.Identity.Name;
var peopleManager = new PeopleManager(clientContext);
var properties = peopleManager.GetPropertiesFor(loginName);
clientContext.Load(properties, p => p.PersonalUrl, p => p.UserProfileProperties);
clientContext.ExecuteQuery();

Is there a way where I can catch UserProfileNoUserFoundException exception instead of exception "Forbidden"?

0

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.