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

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.load(userProfileProperties);
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) {
 alert("Error");
}

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

share|improve this question
add comment

3 Answers 3

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
add comment

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
add comment

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. –  dotnetmirror.com May 15 '13 at 5:50
add comment

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.