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

In the SharePoint application, we have a left menu in which we are showing current user profile picture. In order to get the user profile image, we are using SharePoint client object model using below code.

var clientContext = new SP.ClientContext.get_current();
var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);
userProfileProperties = peopleManager.getMyProperties()
clientContext.executeQueryAsync(onSuccess, onFail);

function onSuccess() {
var up_url = userProfileProperties.get_pictureUrl();
if (up_url !== null) {
    $('.profile-image img').attr('src', up_url);     

function onFail(sender, args) {

But each time user login to site, it asking for credentials for image.

share|improve this question

There doesn't seem to be anything wrong with your code from the surface with a read through.

So it could be that you need to add your site to the safe zones of your browser. Have you checked this in other browsers?

If this is the case for IE go to Tools > Internet Options > Security > Local Intranet > Sites > Advanced > Then add your site here.

If this does work then if you are a domain Admin you can change the policy globally.

However if this is not the case then it leads me to say you would need to debug this with fiddler. You can then ascertain the reason behind the multiple authentication.

share|improve this answer

We fixed the issue by using below code

var userpicUrl = '/_layouts/15/userphoto.aspx?accountname=' + userProfileProperties.get_accountName() + '&size=M&url=' + userProfileProperties.get_pictureUrl();
$('.profile-image img').attr('src', userpicUrl );
share|improve this answer

Code seems to be ok. But I suggest you put alert after each line and check the code again you will not get alert if any line is throwing error.

Best way to debug on client side.

share|improve this answer
We are not getting any error from client object code. Instead its asking for user credentials again while fetching image src from user profile. – May 15 '13 at 5:50

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.