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 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
        {
            get
            {
                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

1 Answer 1

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);

}

Reference

share|improve this answer

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.