Webpart:Impersonation / RunWithElevatedPrivileges

时间:2010-08-09 07:14:16

标签: c# moss

我正在使用MOSS 07& WindowsServer2003上的VisualStudio 07(c#)

我的问题是我希望从一个Sharepoint访问另一个Sharepoint。 在SharePoint_1中是我想从SharePoint_2中读出的SPList。

我的研究结果是IMPERSONATION和RUN_WITH_ELEVATED_PRIVILEGES。 通过模拟我可以读出我连接的SPSite的html代码,但是如何获得我想要的List? 当我尝试RunWithElevatedPrivileges时,我必须从用户表单中获取SharePoint_1的站点。但由于FileNotFoundException,我无法得到用户(即使我得到了他的名字)。

我该如何解决这个问题?

由于

有些事我忘了告诉。 在List is Attachments中我也需要访问它们。

解决此问题的最佳方法是什么? 希望它不是很棘手,因为我在5周前第一次使用Sharepoint,并且对此不太熟悉:))

由于

1 个答案:

答案 0 :(得分:0)

使用SPSecurity.RunWithElevatedPrivileges时,您无需指定用户。如果您使用,我认为您会好的:

[url] =其他网站集的网址

SPSecurity.RunWithElevatedPrivileges(() => {
    using (var site = new SPSite("[url]")) {
        using (var web = site.OpenWeb()) {
            // Access list here
        }
        site.RootWeb.Dispose();
    }
});