2

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

[WebMethod]
        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())
                {
                    try
                    {
                        upcm.StartSynchronization();
                        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.

thanks,

1 Answer 1

1

Try adding

Context.Items["FormDigestValidated"] = true;
SPUtility.ValidateFormDigest();

to the beginning of your method.

Edit:

Revised code above.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.