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

I'm trying to kick off the user profile syc using a web service. Here is what i've tried :

        public string runUserProfileService()
            var message = "";

            using (SPSite site = new SPSite("http://servernamehere/"))
                site.AllowUnsafeUpdates = true;
                SPServiceContext context = SPServiceContext.GetContext(site);
                UserProfileConfigManager upcm = new UserProfileConfigManager(context);

                if (!upcm.IsSynchronizationRunning())
                        message = "running";
                        return message;
                    catch (Exception ex)
                        message = ex.Message;
                        return message;

                message = "running";

            return message;

Here is the exception that I continue to get:

The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.

Any help would be appreciated.


share|improve this question
up vote 1 down vote accepted

Try adding

Context.Items["FormDigestValidated"] = true;

to the beginning of your method.


Revised code above.

share|improve this answer
I added this to the top of the method. When it hits this line I get the same error as before. – ironman Feb 8 '13 at 20:17
How are you calling the webservice? Is it through a http get? – Steve Lineberry Feb 9 '13 at 1:10
Ok, I changed the code in my answer. Try adding that at the top. – Steve Lineberry Feb 9 '13 at 1:13

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.