1- AllowUnsafeUpdates is used when we try to update something to the sharepoint database .In most case this might be a simple list .
2-When you try to update an item or list located in the SPWeb instance or update the instance itself you will most likely set the AllowUnsafeUpdates property to true before calling the update. If you don't you will get the following error:
The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.
Example:
SPWeb web = ...;
web.AllowUnsafeUpdates = true;
web.Title = "Web Title Change" + DateTime.Now.ToShortTimeString();
web.Update();
What I have learned the hard way today is that when you set the AllowUnsafeUpdates property to true and your code jumps to the catch block of a try/catch statement, that property will be set to false again.
Example:
SPWeb web = ...;
try{
web.AllowUnsafeUpdates = true; throw new Exception("Something went really wrong underway !");
}catch (Exception ex)
{ // At this point the web.AllowUnsafeUpdates is false. Before we can update the item we will need to set it to true !
web.AllowUnsafeUpdates = true; SPListItem errorItem = web.Lists["ErrorLog"].Items.Add();
errorItem["Title"] = "Web.Title update failed";
errorItem["Description"] = ex.ToString();
errorItem.Update();
}
Central Administration General Settings Error
Updates are currently disallowed on GET requests. To allow updates on a GET, set the 'AllowUnsafeUpdates' property on SPWeb.
When you work on Central Administration ,
1) Application Management -> Web Applications -> Manage web applications
2) Select a web application -> General Settings. You get the below error :
"Updates are currently disallowed on GET requests. To allow updates on a GET, set the 'AllowUnsafeUpdates' property on SPWeb."
Fix :
Open Sharepoint 2010 Management powershell
Put the below code in :
$w = get-spwebapplication http://The_Web_App
$w.HttpThrottleSettings
$w.Update()
No comments:
Post a Comment