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