SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

I have custom claims provider which uses user profile service to get some data when resolving claims for user. I'm creating UserProfileManager this way:

private UserProfileManager UserProfileManager
                if (_upm == null)
                    SPServiceContext serviceContext = SPServiceContext.Current;                    
                    _upm = new UserProfileManager(serviceContext);
                return _upm;

It works when I'm using gui for user management, because SPServiceContext.Current is present. I also have a timer job which performs some operation on user permissions, so it also uses my custom claim provider. The problem is, that there is no SPServiceContext.Current in OWSTIMER process and I can't create UserProfileManager instance.

How can I obtain service context for UserProfileManager in timer job (OWSTIMER process)?

share|improve this question

Here is how you get SPServiceContext:

public void UserProfileSample()
    //get current service context
    string websiteUrl = "http://SampleName";
    SPSite site = new SPSite(strUrl);
    SPServiceContext serviceContext = SPServiceContext.GetContext(site);

   //initialize user profile config manager object
   UserProfileManager upm = new UserProfileManager(serviceContext);



share|improve this answer

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.