Unnie Ayilliath

Microsoft 365 | Azure | Identity Solutions

Update User Profile Property on Get Requests like Page_Load

When ever you are trying to use user profiles in SharePoint , things can get tricky if you don’t get the settings right. Here i am discussing about an issue i recently faced when trying to update the custom user profile property in a Visual webpart in SharePoint 2010.Now you might face similar issue if you are trying to edit anything like user profile property, term store etc in GET requests.

Issue: Application throws an error “UPDATES ARE CURRENTLY DISALLOWED ON GET REQUESTS.TO ALLOW UPDATES ON A GET, SET THE ‘ALLOWUNSAFEUPDATES’ PROPERTY ON SPWEB ” when you are trying to update the User profile property on Page_Load.


Now i already set the allowunsafeupdates property to true, I checked whether the property is set to editable by user in User profile service and everything looked good but this problem doesn’t seem to resolve. After some more debugging i noticed  that even though i have set allowunsafeupdates property to true , it automatically was reset to false by SharePoint , because allowunsafeupdates property is ignored in all GET requests.

Workaround: The workaround i got for this solution after trying of different methods is that temporarily  set the current HttpContext to null. When the current HttpContext is null, SharePoint does not know that the request was  a GET request and restore the HttpContext back to original after update.

HttpContext currentContext = HttpContext.Current;//store current context to a temp variable
HttpContext.Current = null;//set current context to null
currentProfile[“PropertyName”].Value = PropertyValue;//set property value
currentProfile.Commit();//update user profile
HttpContext.Current = currentContext;// reset the httpcontext

Hope this post saves your time..!!!

Published by

One response to “Update User Profile Property on Get Requests like Page_Load”

  1. I love u…it worked for me….i had lost all hope until i found your blog…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Website Powered by WordPress.com.

%d bloggers like this: