2009-02-26 50 views
1

我們冒充SharePoint用戶並嘗試訪問列表項。SharePoint,在模擬後拋出異常

using (SPSite site = new SPSite(BAH.SN.Properties.Settings.Default.RootSiteUrl, new SPUserToken(currentUser.ImpersonationToken))) 
     { 
      using (SPWeb web = site.RootWeb) 
      { 
       SPList list = web.GetList(BAH.SN.Properties.Settings.Default.CommunitiesListPath); 
       if (list != null) 
       { 
        SPQuery query = CAMLHelper.GetSPQueryForCommunityListByOwner(user.UserName); 
        SPListItemCollection items = list.GetItems(query); 
        if (items != null && items.Count > 0) 
        { 
         // Read here 
        } 
       } 
      } 
     } 

我們能夠拿到列表上的把手,但只要我們嘗試訪問的SPListItemCollection「項目」的任何財產,我們得到一個COM異常:532459699.

我們正在運行FBA並且用戶調用此代碼是匿名用戶。

親切的問候,

回答

0

您是否嘗試過使用ElevatedPrivileges代替令牌?

SPSecurity.RunWithElevatedPrivileges(delegate() { 
    //your code inside here, except use the SPSite ctor that only takes the url and get that frome SPContext: 
    // new SPSite(SPContext.Current.Site.Url); 
} 

也請提供完整的堆棧跟蹤,以給我們最好的方式來幫助你。 如果您不知道如何在web.config中啓用該功能,請檢查該問題的許多博客文章之一here

0

SPSecurity.RunWithElevatedPrivileges將運行系統帳戶中的代碼。這不會解決他/她的問題。