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();
}