[SharePoint 2010] Updates are currently disallowed on GET requests. To allow updates on a GET, set the ‘AllowUnsafeUpdates’ property on SPWeb.

I was working on a WCF web service that is hosted by SharePoint 2010 that provisions a users My Site and I kept getting this error message when trying to run the service:

Updates are currently disallowed on GET requests. To allow updates on a GET, set the 'AllowUnsafeUpdates' property on SPWeb.

In searching the issue, I found a workaround on the MSDN forums that works quite well: set the current HttpContext to null. When the current HttpContext is null, SharePoint does not know that the request was made during a GET request.

// Save the current HttpContext to a variable to reuse later
var context = HttpContext.Current;
var serviceContext = SPServiceContext.Current;
var userProfileManager = new UserProfileManager(serviceContext);
var userProfile = userProfileManager.GetUserProfile(SPContext.Current.Web.CurrentUser.LoginName);
if (userProfile != null)
{
	if (userProfile.PersonalSite == null)
	{
		// Set the current HttpContext to null
		HttpContext.Current = null;
		userProfile.CreatePersonalSite();
	}
}
// Reset the HttpContext
HttpContext.Current = context;

I found this extremely helpful and wanted to share.

John Chapman

Hello, I'm John Chapman. I am a SharePoint Developer for Sitrion (formerly NewsGator) living in Denver, Colorado. I develop solutions using SharePoint and .NET, and I thrive on the challenge of writing code to overcome the impossible, annoying, or otherwise difficult obstacles.

More Posts - Website - Twitter - LinkedIn - Google Plus