tags:

views:

99

answers:

1

I have a hidden webpart that read query string value "optout=Yes" . This optout = Yes, then I need to update profile property. If you see in my code. It is failing at "userprof.Commit()" and throwing "Updates are currently disallowed on GET requests. To allow updates on a GET, set the 'AllowUnsafeUpdates' property on SPWeb" . Any solution for this?

private void OptOutMemberInvitation()
{

  SPSecurity.RunWithElevatedPrivileges(delegate()
  {

    //update the invitee's Profile property
    UpdateInviteeOptOutProfile(InviteeConstitID);

  });
}
private void UpdateInviteeOptOutProfile(string inviteeSiteColUrl)
{
  ServerContext sc = ServerContext.Current;
  UserProfileManager upm = new UserProfileManager(sc);
  //Get the user profile
  Microsoft.Office.Server.UserProfiles.UserProfile userprof = upm.GetUserProfile(MemberConstitID);
  SPWeb web = userprof.PersonalSite.RootWeb;

  //make sure we can update our list
  web.AllowUnsafeUpdates = true;
  web.Update();
  //Update the OptOut Property on the user's profile.
  userprof["OptOut"].Value = "Yes";
  userprof.Commit(); //Fails here
  //update the list item to persist it to list

  web.AllowUnsafeUpdates = false;
  //siteCol.Close();
  //siteCol.Dispose();
}
A: 

Looks like you could be using two SPWeb objects, and setting AllowUnsafeUpdates on the wrong one. One would be connected with current server context and the other is userprof.PersonalSite.RootWeb. You'd be setting AllowUnsafeProperties on the RootWeb, and updating the SPWeb in profile (if there is one).

BTW don't forget to do a web.Update() after you set AllowUnsafeProperties at the end.

kerray
I am using this one too. still getting error. UserProfile userprof = man.GetUserProfile(SPContext.Current.Web.CurrentUser.LoginName); SPSite site = SPContext.Current.Site; SPWeb web = site.OpenWeb(); //make sure we can update our list web.AllowUnsafeUpdates = true; web.Update(); //Update the OptOut Property on the user's profile. userprof["OptOut"].Value = "Yes"; userprof.Commit(); web.AllowUnsafeUpdates = false;
James123
is it possible to you change my code? please
James123