2012-03-06 66 views
2

我尝试更新的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; 
} 

几次这样的事情都在那里,因为我已经搜查四周,尝试不同的东西。建议?

回答

0

我们现在在做的是写入隐藏的SP用户配置文件列表来欺骗它,直到AD同步发生。这不是最好的答案,但它是我迄今发现的唯一答案。如果有人来,我会很乐意接受更好的答案。

SPSecurity.RunWithElevatedPrivileges(() => 
        { 
         using (var site = new SPSite(CurrentWeb.Site.Url)) 
         { 
          using (var web = site.OpenWeb(CurrentWeb.ID)) 
          { 
           web.AllowUnsafeUpdates = true; 
           SPList userInfo = web.Site.RootWeb.Lists["User Information List"]; 
           SPListItem userItem = userInfo.Items.GetItemById(_SelectedUser.ID); 
           userItem["Work phone"] = tbPhone.Text; 
           userItem["Work e-mail"] = tbEmail.Text; 
           userItem["company"] = tbCompany.Text; 
           userItem.Update(); 
          } 
         } 
        }); 
0

你最终得到了这个工作吗?根据我的经验,模拟对用户配置文件服务不起作用。它倾向于使用HttpContext.Current.User.Identity而不是System.Security.Principal.WindowsIdentity.GetCurrent()。尝试将HttpContext.Current设置为null并查看发生了什么。

还请记住,当前标识必须具有托管用户配置文件特权。

+0

感谢您的答案,但我尝试设置的HttpContext为null。我尝试过和没有'模拟'。我已经确认当时使用的帐户是农场管理员(开发环境)。我们现在正在做的是写入隐藏的SP用户配置文件列表并欺骗它,直到AD同步发生:P – Eonasdan 2012-03-12 11:39:14

2

这个异常的问题不是你的代码。这是你想改变的领域的腐败设置。 请看下面的post,因为这个描述了解决方案以及您在现场设置中必须改变的内容。

http://msscorner.de/en/2011/10/18/userprofile-manager-eigenschaft-kann-nicht-bearbeitet-werden-diese-eigenschaft-kann-nur-von-einem-administrator-geandert-werden/

我希望它能帮助

+0

谢谢。我在7个月前问过这个问题,而且我们已经从这个问题转移了出来。这似乎是我做的,但我不记得了。 – Eonasdan 2012-10-17 12:10:02

0

执行下面的步骤,这些将解决此问题:

1)重新启动SharePoint管理服务和SharePoint定时从SERVICES.MSC
服务 2)使用powershell停止并启动用户配置文件服务
3)执行IISRESET在所有Web前端服务器和应用程序服务器上以及
4)现在清理浏览器缓存并访问该URL。

0

无论谁还在试图解决这个问题,我发现一个解决方案感谢this博客。

在短:

你必须运行高架更新,你必须设置HttpContext.Current为null。我个人的猜测是,这是SharePoint中的一个错误,如果设置了上下文,那么它的行为会出错。

代码片段:

SPSecurity.RunWithElevatedPrivileges(() => 
{ 
    HttpContext httpContext = HttpContext.Current; 
    try 
    { 
     SPServiceContext serviceContext = SPServiceContext.GetContext(httpContext); 
     HttpContext.Current = null; // Hack !!! 
     UserProfileManager upm = new UserProfileManager(serviceContext); 
     //.. update your property which has "IsAdminEditable" set to true and "IsUserEditable" set to false 
    } 
    finally 
    { 
     //restore old context 
     HttpContext.Current = httpContext; 
    } 
}