I want to update the user profile details through the code however it is throwing the below exception "Updates are currently disallowed on GET requests. To allow updates on a GET, set the 'AllowUnsafeUpdates' property on SPWeb".
what am I missing? and how to fix?
Code
private void updateUserProfileChanges(string _mySiteLocal, string _mySiteCentral)
{
string currentUser ="";
string localLastUpdateDate ="";
currentUser = SPContext.Current.Web.CurrentUser.LoginName;
using (SPSite localMySite = new SPSite(_mySiteLocal))
{
//using(SPWeb web = localMySite.OpenWeb())
//{
//web.AllowUnsafeUpdates = true;
//web.Update();
SPSecurity.RunWithElevatedPrivileges(delegate
{
SPServiceContext localContext = SPServiceContext.GetContext(localMySite);
UserProfileManager localProfileManager = new UserProfileManager(localContext);
UserProfile localUserProfile = localProfileManager.GetUserProfile(currentUser);
try
{
if (localUserProfile.GetProfileValueCollection("LocalLastUpdateDate").Count >= 1)
{
localLastUpdateDate = localUserProfile["LocalLastUpdateDate"].ToString();
}
else
{
localLastUpdateDate = DateTime.Now.ToString();
localUserProfile["CellPhone"].Value = "nnnnnnnnnnn";
localUserProfile.Commit(); //throws an exception
}
}
catch(Exception ex)
{
}
});
//web.AllowUnsafeUpdates = false;
//web.Update();
//}
}
}