0

我试图获取确定用户财产的当前隐私状态。我没有什么奇特的想法,我只需要知道财产是如何配置的,以便我可以做出决定。这是我的代码:通过Sharepoint 2010获取财产隐私

 SPSecurity.RunWithElevatedPrivileges(delegate() 
     { 
      using (SPSite site = new SPSite("http://sp2010dev:3767")) 
      { 
       context = SPServiceContext.GetContext(site); 
       psm = ProfileSubtypeManager.Get(context); 
       upm = new UserProfileManager(context, false); 
       UserProfile user = upm.GetUserProfile(false); 
       Privacy privacy = user["SPS-Skills"].Privacy; 
      } 
     }); 

我获得这个消息:拒绝访问:您可以精心取回自己的个人资料的隐私设置,除非你是管理员。

任何线索?

+0

当您使用SPSecurity.RunWithElevatedPrivileges时,可以有效地将代码作为IIS AppPool用户运行。该用户是网站上的网站集管理员吗? – 2012-03-09 14:14:57

+0

Nop,它是MySite。我正试图让一位同事隐私政策显示或隐藏该媒体资源。为了简单起见,我的代码示例中只有一名用户。 – 2012-03-09 14:17:12

+0

如果yuo're击中mysite,考虑不与高架privs运行.. – 2012-03-09 14:32:59

回答

3

奇怪!它应该工作你的代码。不知道为什么它没有运行?

你应该试试这个

try 
     { 
      SPUser AdminUser = SPContext.Current.Web.AllUsers[@"SHAREPOINT\SYSTEM"]; 
      var superToken = AdminUser.UserToken; 
      HttpContext con = HttpContext.Current; 
      SPSecurity.RunWithElevatedPrivileges(delegate() 
      { 
       using (SPSite site = new SPSite(SPContext.Current.Site.Url, superToken)) 
       { 
        SPServiceContext context = SPServiceContext.GetContext(site); 
        HttpContext.Current = null; 
        UserProfileManager upm = new UserProfileManager(context, false); 
        \\get useprofile code 
       } 
      }); 
      HttpContext.Current = con; 
     } 
     catch (Exception ex) 
     { 
      throw ex; 
     } 

啤酒花这会有所帮助。

+0

完全有效!现在我拥有你我的第一个出生。非常感谢! – 2012-03-12 10:55:09

+0

欢迎:) – Jigs 2012-03-12 13:14:59

+0

这实际上有效。好伙伴。 – Fox 2016-02-19 00:35:49