Tuesday, April 7, 2009

Updates are currently disallowed on GET requests

Scenario:
I was trying to update one of the web properties and got the following error.

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

Solution:
Simple, You need to set AllowUnsafeUpdates to true before making any update to web object and later it can be turned back to false.

Code:

SPWeb objWeb = SPContext.Current.Web;
objWeb.AllowUnsafeUpdates = true;

// To do ( Write code here )

objWeb.Update();
objWeb.AllowUnsafeUpdates = false;


Note:
This will happen only in UI elements making GET request. You are not required to do this in Feature Receivers

3 comments:

Anonymous,  April 17, 2011 at 12:41 PM  

I did exactly that and did not work. My code is in a webpart.
Can you help please?

Sandeep April 17, 2011 at 12:51 PM  

hmmm.. ensure you have deployed ur changes properly and did IISReset also. If you are still getting error, post a question with code snippet in Microsoft Development forum. I will try to reply

.Net Follower May 20, 2011 at 11:42 PM  

Hello! When you have GET request and call BreakRoleInheritance, web.AllowUnsafeUpdates=true doesn't help. I described it and a workaround in my blog http://dotnetfollower.com/wordpress/2011/03/sharepoint-updates-are-currently-disallowed-on-get-requests/