2009-02-26 70 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将运行系统帐户中的代码。这不会解决他/她的问题。