Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

'AllowUnsafeUpdates' property on SPWeb - Updates are currently disallowed on GET requests

  Asked By: Reynaldo    Date: Apr 12    Category: Sharepoint    Views: 6861

Anyone run into this? Here's the exact error:

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

What I'm trying to do is to add an Announcement programatically. While I guess I could do the AllowUnsafeUpdates, I'm wondering if there is a way to do it without doing that. I'd like to do it the safest way possible. I'm utilizing the SmartPart and using my own UserControl. Anyway I can make this be a "POST"? I might just be really dumbed down right now as it's Friday, so please take it easy on me if it's really simple! haha Any hoo, here's my code:

foreach (SPList list in SPWeb.Lists)


Response.Write (list.Title + list.GetType().ToString() + "<br>");

if (list.Title == "Announcements")


SPListItemCollection listItems = list.Items;

SPListItem newitem = listItems.Add();

newitem["Title"] = "Test" + list.Items.Count.ToString();

newitem["Body"] = "testbody for item #" + list.Items.Count.ToString();

newitem["Expires"] = System.DateTime.Now.AddDays(1);







3 Answers Found

Answer #1    Answered By: Victor Hughes     Answered On: Apr 12

Yes, it is maddening. However, you can potentially see why they want a post.
A get can be completely contained in the query string.

So, you will need to set  AllowUnsafeUpdates = true or
change to a post  and include a <formdigest> tag or the following code in
your Page_Load event:

SPGlobalAdmin globalAdmin = new SPGlobalAdmin();
Context.Items[SPGlobalAdmin.RequestFromAdminPort] = true;
Page.RegisterHiddenField("__REQUESTDIGEST", globalAdmin.AdminFormDigest);

Answer #2    Answered By: Gordon Blair     Answered On: Apr 12

This is probably a stupid question, but if I'm programming an ASCX page for a web part (hosted in the SmartPart), how can I change the page over to a POST instead of a GET? Thanks for your help!

Answer #3    Answered By: Barry Burke     Answered On: Apr 12

I would assume you change:

<form runat="server">


<form method="post" runat="server">

But I'm not in a place where I can test that out. I hate to admit it but I
usually just take the shortcut and use AllowUnsafeUpdates.