Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I’m in quite a bind here. I just need to update a taxonomy field in a list item, but I keep getting an “Updates are currently disallowed on GET requests. To allow updates on a GET, set the 'AllowUnsafeUpdates' property on SPWeb” exception.

The code is being executed from within a SharePoint workflow that automatically runs when a new item is added to the list. The workflow was developed from scratch in Visual Studio.

I have tried setting AllowUnsafeUpdates = true on the item’s Web property, the item’s Web.Site, and the item’s Web.Site.RootWeb (which should be the same as the item’s web because the list is in the root web). Also tried calling the Update() method on the web object(s) after setting allow unsafe updates, as one blog suggested.

I have also tried running the code inside SPSecurity.RunWithElevatedPrivileges(), and tried setting SPGlobalAdmin.AllowUnsafeUpdates = true.

The stack trace I get every time is this:

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) [According to .NET reflector the above methods should NOT be called, but here they are in the stack trace?? TaxonomyField.GetValidatedString() does not call TaxonomyField.ValidTaxonomyFieldValue() ] at Microsoft.SharePoint.Taxonomy.TaxonomyField.GetValidatedString(Object value) at Microsoft.SharePoint.Taxonomy.TaxonomyField.SetFieldValue(SPListItem item, TaxonomyFieldValue taxValue) at Microsoft.SharePoint.Taxonomy.TaxonomyField.SetFieldValue(SPListItem item, Term term, Int32 lcid) at Microsoft.SharePoint.Taxonomy.TaxonomyField.SetFieldValue(SPListItem item, Term term) [Customer specific code redacted] at System.Workflow.ComponentModel.Activity.RaiseEvent(DependencyProperty dependencyEvent, Object sender, EventArgs e) at System.Workflow.Activities.CodeActivity.Execute(ActivityExecutionContext executionContext) at System.Workflow.ComponentModel.ActivityExecutor1.Execute(T activity, ActivityExecutionContext executionContext) at System.Workflow.ComponentModel.ActivityExecutor1.Execute(Activity activity, ActivityExecutionContext executionContext) at System.Workflow.ComponentModel.ActivityExecutorOperation.Run(IWorkflowCoreRuntime workflowCoreRuntime)

One thing I do not understand is how the last 6 methods in the stack trace are getting called. When I look at TaxonomyField.GetValidatedString(Object value) in .NET reflector all it does is return value.ToString(). The value parameter passed in has the type TaxonomyFieldValue. I looked at TaxonomyFieldValue.ToString(), which is overridden, but all it does is use a string builder to concatenate some string values. Nothing that I can see calls the TaxonomyField.ValidTaxonomyFieldValue() method, so how is it showing up in the stack trace?

I’ve seen a couple of blog posts say that to get around this error you need to move your code so that it executes in a postback so that there are user credentials available or something. They all say they took the code that was throwing the exception and placed it inside a button click handler so it executed on postback. I don’t see any way to even try this out since we are using a workflow that starts automatically?

Any help is appreciated, Thanks!

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Sounds like you're probably setting AllowUnsafeUpdates on the wrong SPWeb (take a look here for a good article). How are you getting the SPWeb?

You may try opening a new SPWeb, setting AllowUnsafeUpdates, and then running your code. You should not need to call Update() after setting AllowUnsafeUpdates.

share|improve this answer
    
I'm getting the SPWeb through the SPListItem object that is passed into my workflow. _item.Web.AllowUnsafeUpdates = true; Maybe I need to get the SPWeb from the TaxonomyField object? I have it working now and what I did was one option that article mentions. I temporarily set the HttpContext.Current to null, then restored the value afterwards. Thanks. –  user1925 Dec 23 '10 at 23:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.