【问题标题】:SharePoint, throwing Exception after impersonationSharePoint,模拟后抛出异常
【发布时间】:2013-10-17 00:16:34
【问题描述】:

我们正在模拟 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“items”的任何属性,我们就会得到一个 COM 异常:532459699。

我们正在运行 FBA,调用此代码的用户是匿名用户。

亲切的问候,

【问题讨论】:

    标签: sharepoint


    【解决方案1】:

    SPSecurity.RunWithElevatedPrivileges 将在系统帐户中运行代码。这不会解决他/她的问题。

    【讨论】:

      【解决方案2】:

      您是否尝试过使用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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-07-25
        • 1970-01-01
        • 1970-01-01
        • 2017-07-11
        • 1970-01-01
        • 2023-03-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多