我尝试更新的SharePoint 2010个用户个人资料,我不断收到此错误:更新用户配置文件抛出PropertyNotEditableException在SharePoint 2010
Microsoft.Office.Server.UserProfiles.PropertyNotEditableException: Property Not
Editable: This property can only be modified by an administrator.
at Microsoft.Office.Server.UserProfiles.UserProfileValueCollection.
CheckUpdatePermissions()
我首先更新AD与代码独立的块(其中工程)。我们正在使用配置文件同步服务,因此该值最终会传播,但我们希望同时更新SP配置文件以立即显示更改。
代码:
using (System.Web.Hosting.HostingEnvironment.Impersonate())
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
Response.Write(System.Security.Principal.WindowsIdentity.GetCurrent().Name);
using (var site = new SPSite(SPContext.Current.Site.ID))
{
try
{
SPServiceContext sc = SPServiceContext.GetContext(site);
UserProfileManager userProfileMangager = new UserProfileManager(sc);
SPUser user = site.RootWeb.EnsureUser(loginName);
UserProfile profile = userProfileMangager.GetUserProfile(loginName);
try
{
profile["WorkEmail"].Value = tbEmail.Text;
profile["WorkPhone"].Value = tbPhone.Text;
profile["company"].Value = tbCompany.Text;
profile.Commit();
}
catch (Exception ex)
{
lblMesssage.Text = ex.ToString() + "<br/>";
lblMesssage.Visible = true;
}
}
catch (Exception ex)
{
lblMesssage.Text = ex.ToString();
lblMesssage.Visible = true;
}
}
});
panComplete.Visible = true;
panForm.Visible = false;
waiting.Visible = false;
litSuccess.Visible = true;
}
几次这样的事情都在那里,因为我已经搜查四周,尝试不同的东西。建议?
感谢您的答案,但我尝试设置的HttpContext为null。我尝试过和没有'模拟'。我已经确认当时使用的帐户是农场管理员(开发环境)。我们现在正在做的是写入隐藏的SP用户配置文件列表并欺骗它,直到AD同步发生:P – Eonasdan 2012-03-12 11:39:14