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

  • Question

  • I get the above specified error on the following code :
    
    I don't have any clue why.
    
            using (SPSite site = SPContext.Current.Site)
            {
              using (SPWeb web = site.OpenWeb("/NewSite/"))
              {
    
                //list that contain the item
                SPList list = web.Lists[listMD];
    
                TermSet termSet = null;
                TaxonomySession txs = new TaxonomySession(web.Site);
                
                //the item that have to be updated
                SPListItem item = list.GetItemById(id);
    
                //set the taxonomy field to the name of taxonomy field column of the item
                TaxonomyField managedField = item.Fields[fieldMD] as TaxonomyField;
    
                //check if taxonomy field exist
                if (managedField != null)
                {
                  //check if the requested termMD exist or not in TermStore
                  termSet = txs.DefaultSiteCollectionTermStore.GetTermSet(managedField.TermSetId);
                  Term term = termSet.GetTerms(termMD, false).FirstOrDefault();
    
                  // if the requested termMD does not exist in TermStore then we create the new Term
                  if (term == null)
                  {
                    createNewTerm(termSV, termMD);
                  }
                  termSet = txs.DefaultSiteCollectionTermStore.GetTermSet(managedField.TermSetId);
                  Term termNew = termSet.GetTerms(termMD, false).FirstOrDefault();
    
                  managedField.SetFieldValue(item, termNew);
                  item.SystemUpdate();
                }
                web.AllowUnsafeUpdates = false;
              }
    
            }
    

    Thanks for helping.
    OvidiuG
    • Moved by Wayne Fan Thursday, June 30, 2011 7:29 AM It's SharePoint 2010 issue, thanks. (From:SharePoint - Development and Programming (pre-SharePoint 2010))
    Wednesday, June 29, 2011 7:53 AM

Answers

  • You are not allowed to create new termsets in a GET request.

    AllowSafeUpdates is ignored on GET requests.

    I think that web.ValidateFormDigest is called by SharePoint somewhere. When you try to create a new TermSet. ValidateFormDigest will always throw the exception you experience on a GET request.

    If you have a stacktrace. We can decompile the code and verify the problem.

    • Marked as answer by Wayne Fan Thursday, July 7, 2011 8:06 AM
    Thursday, June 30, 2011 9:07 AM

All replies

  • Hi OvidiuG,

     

    According the error message, you should Enable set “AllowUnsafeUpdates” property to true before you update it.

    So try to do some changes with the code as following:

    using (SPWeb web = site.OpenWeb("/NewSite/"))

    {

                    web.AllowUnsafeUpdates = true;

                    //other code

     

    Also, the Termset is new feature in SharePoint 2010. So I will move this thread to SharePoint 2010.

     

    Thanks,

    Wayne Fan

    TechNet Subscriber Support in forum

    If you have any feedback on our support, please contact  tnmff@microsoft.com.

    Thursday, June 30, 2011 7:27 AM
  • Thanks for the answer, but even with web.AllowUnsafeUpdates = true is not working.

    I have the same error.


    OvidiuG
    Thursday, June 30, 2011 7:44 AM
  • You are not allowed to create new termsets in a GET request.

    AllowSafeUpdates is ignored on GET requests.

    I think that web.ValidateFormDigest is called by SharePoint somewhere. When you try to create a new TermSet. ValidateFormDigest will always throw the exception you experience on a GET request.

    If you have a stacktrace. We can decompile the code and verify the problem.

    • Marked as answer by Wayne Fan Thursday, July 7, 2011 8:06 AM
    Thursday, June 30, 2011 9:07 AM
  • Hi Anders,

    how can i fix it? pls help us on this. i have the same error... :(

    Wednesday, March 28, 2012 4:39 AM
  • Hi Anders,

    Below is my stacktrace, I'm facing the same issue as above, can you give me any solution ?

       at Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx)
       at Microsoft.SharePoint.Library.SPRequest.ValidateFormDigest(String bstrUrl, String bstrListName)
       at Microsoft.SharePoint.SPWeb.ValidateFormDigest()
       at Microsoft.SharePoint.Taxonomy.TaxonomyField.AddTaxonomyGuidToWss(SPSite site, Term term, Boolean isKeywordField)
       at Microsoft.SharePoint.Taxonomy.TaxonomyField.ValidateTaxonomyFieldValue(TaxonomyFieldValue taxFieldValue)
       at Microsoft.SharePoint.Taxonomy.TaxonomyField.ValidTaxonomyFieldValue(TaxonomyFieldValue taxFieldValue)
       at Microsoft.SharePoint.Taxonomy.TaxonomyField.ValidMultiTaxonomyFieldValue(TaxonomyFieldValueCollection taxFieldCollection)
       at Microsoft.SharePoint.Taxonomy.TaxonomyField.GetValidatedString(Object value)
       at Microsoft.SharePoint.Taxonomy.TaxonomyField.SetFieldValue(SPListItem item, TaxonomyFieldValueCollection taxValueCollection)
       at Microsoft.SharePoint.Taxonomy.TaxonomyField.SetFieldValue(SPListItem item, ICollection`1 terms, Int32 lcid)
       at Microsoft.SharePoint.Taxonomy.TaxonomyField.SetFieldValue(SPListItem item, Term term, Int32 lcid)
       at Microsoft.SharePoint.Taxonomy.TaxonomyField.SetFieldValue(SPListItem item, Term term)
       at ETenantExportToExcel.Layouts.ETenantExportToExcel.Export.<>c__DisplayClass4.<UploadPDFData>b__3()

    Thanks


    VOTE, if you find this as HELPFUL // Manivannan Nagarajan

    Thursday, October 4, 2012 8:47 AM
  • Great...

    The following fix worked out for me...

    I just turned theHttpContext.Current into NULL before update &

    then revert back the  HttpContext.Current  to normal after my update

    Thanks to http://community.bamboosolutions.com/blogs/bambooteamblog/archive/2008/05/15/when-allowunsafeupdates-doesn-t-work.aspx


    VOTE, if you find this as HELPFUL // Manivannan Nagarajan

    Thursday, October 4, 2012 11:30 AM