Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

When trying to update field I get Error: "Updates are currently disallowed on GET requests. To allow updates on a GET, set the 'AllowUnsafeUpdates' property on SPWeb."

$
0
0

Hi,

I have just added a peopleEditor Control to a SharePoint Farm Server Solution. The WebPart already had a peopleEditor control, so I replicate the function to update the item. I understand that this is a formdigest issue as when I run the  SPUtility.ValidateFormDigest(); command before RunwithElevatedPriviledges I get this error. I have removed the ValidateFormDigest to test and it has the same error on the item.Update(). Here is code that has been replicated. Name changed from "Requestor" to "Consumer"

  public static bool UpdateBookingConsumer(int BookingID, SPUser user)
        {
            bool bRet = false;
            SPUser _user = null;

            if (user != null)
            {
                _user = user;
                try
                {
                    SPUtility.ValidateFormDigest();

                    SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        using (SPSite site = new SPSite(SPContext.Current.Web.Url))
                        {
                            site.AllowUnsafeUpdates = true;
                            using (SPWeb web = site.OpenWeb())
                            {
                                web.AllowUnsafeUpdates = true;

                                SPListItemCollection items = Util.ReadItemByParentId(Util.ConfigurationReadValue("ListNameBooking"), BookingID, ref retErrorMessage);
                                if (items != null)
                                {
                                    foreach (SPListItem item in items)
                                    {
                                        item["Consumer"] = _user;
                                        item.Update();
                                    }
                                }
                                web.AllowUnsafeUpdates = false;
                            }
                            site.AllowUnsafeUpdates = false;
                        }
                    });
                    bRet = true;
                }
                catch (Exception ex)
                {
                    Util.HandleException(ex, System.Reflection.MethodBase.GetCurrentMethod().Name);
                }
            }
            else
            {
                retErrorMessage = ConfigurationReadValue("MSG-SUMMARY-011");       //User Consumer provided is empty or not valid }
            }

            return bRet;
        }
        

Can someone explain to me in laymen's terms how the FormDigest works - lots of articles with people seeming to not really understand what is going on in depth?

The way I understand it is it's only a token made up of user, site etc. So why is this added field throwing this up? 

Do I have to have a placeholder for the new field in the FormDigest somewhere? 

Help Appreciated.

Thanks.

John.  


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>