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'm creating web part that will show user's links and sites. When I'm trying to get context from SPServiceContext information server throws me exception:

No User Profile Application available to service the request. Contact your farm administrator...

This is my code:

SPSecurity.RunWithElevatedPrivileges(delegate()
{
    using (SPSite site = new SPSite(SPContext.Current.Site.ID))
    {
        SPServiceContext context = SPServiceContext.GetContext(site);
        UserProfileManager mgr = new UserProfileManager(context);
        UserProfile userProfile = mgr.GetUserProfile(SPContext.Current.Web.CurrentUser.LoginName);
    }
}

I have checked that "User Profile Service Application" is started. What I'm missing? How to collect user profile details?

Regards

share|improve this question
    
Did you create a user profile service app and started it on one server in the farm? Check Spence blog if you don't know: harbar.net/articles/sp2010ups.aspx –  Marco Scheel Feb 1 '13 at 9:44
    
Yes, User Profile Service is started. User Profile Synchronization Service has status "starting" all the time. –  porterneon Feb 1 '13 at 9:49
    
I'm not 100% sure if this "stuck on starging" is a problem. Not sure if the code should run because this is only the ad sync. but i'm not 100% sure. maybe it is better to first get this thing up and running. check spence harbars blog is has many solutions to the stuck in starting problem. –  Marco Scheel Feb 1 '13 at 12:37
add comment

4 Answers

If UPS is configured and started please check the permissions on the UPS application. As you run with elevated privileges you are using the app pool account of the web app your are hosted on. This account should have permissions for the user profile service app.

Check out this blog post to see the process of configuring permissions (not administrator permissions):

http://blog.mastykarz.nl/granting-permissions-user-profile-service-application-powershell/

For a full reference of the user profile service check out this technet article:

http://technet.microsoft.com/en-us/library/ee721050(v=office.14).aspx

share|improve this answer
    
I have added my account to admin list for user profile service. Nothing has changed. When I click on User Profile Service link, I'm getting exception window. I'm not able to open configuration site for this service. –  porterneon Feb 1 '13 at 10:06
    
Thats not what i told you to do :-) check the app pool account the web app is running. add this account not to the admin permissions add the accounut to the permissions (check the blog post). If you add a user to the admin permissions you grant them administration rights and not the right to use the service app. Thats the concept behind it. Check your app pool account and grant him full control. The user executing the browser can be ignored. –  Marco Scheel Feb 1 '13 at 12:43
add comment

The reason can be that User Profile Service is not associated with the Webapplication. This can be checked by going into CA-->Application Management-->WebApplications--> Select your web application. In the ribbon Select Service Connections. In Configure Service Applications popup ensure that User Profile Service Application is checked.

share|improve this answer
    
User Profile Service Application is checked for this web application. This is main web application on my host. –  porterneon Feb 1 '13 at 9:46
2  
It might be a permissions issue then. Check this link: blogs.technet.com/b/speschka/archive/2010/02/22/… –  Nadeem Yousuf Feb 1 '13 at 9:53
add comment

It sounds like you are on the right track and have done all the correct things. I remember Todd Klindt talking about the User Profile Service Instance saying that it was started even when it wasn't in one of his netcasts.

Check that the SharePoint Administration Service is running on the SharePoint machine running User Profile Service.

Try restarting the Service Instance on the machine that is running User Profile Service, you could use SharePoint Management Console and PowerShell to do this:-

`$serviceInstance = Get-spserviceinstance | ?{$_.TypeName -like "User Profile Service"};

Stop-SPServiceInstance -Identity $serviceInstance;

Start-SPServiceInstance -Identity $serviceInstance; `

Now see if you can now access the User Profile Service Application.

HTH

Cheers

Simon

share|improve this answer
add comment

If all you are doing is displaying profile information for the current user, then there is no need to elevate permissions here. The current user already has permissions to get their own data.

ProfileLoader loader = ProfileLoader.GetProfileLoader(SPServiceContext.Current);
UserProfileManager manager = loader.GetUserProfileManager();
UserProfile profile = manager.GetUserProfile(true);

The GetUserProfile(bool) method gets you the current user's profile to work with, if you pass true, it creates the profile if it doesn't exist.

In general, RunWithElevatedPriveleges and the UserProfileManager do not play well together. UserProfileManager does not support impersonation/elevation.

If you use the ProfileLoader, you will also take advantage of reusing the UserProfileManager that may have been gotten by other web controls already, and so can make your code more performant.

And BTW - the UserProfileSynchronization service would have nothing whatsoever to do with this. That only deals with AD import/export.

share|improve this answer
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.