如何在服务器对象模型中模拟Farm Administrator?

时间:2013-04-26 08:48:21

标签: sharepoint-2010 impersonation sharepoint-api sharepoint-object-model

我们正在使用SharePoint Foundation 2010.我们正在使用服务器对象模型创建内容数据库和网站集。我们在SharePoint中拥有超过1000个用户。由于内容数据库和网站集创建是管理任务,因此只有farm administartor可以执行此操作。在我们的例子中,任何用户都应该能够使用farm administartor帐户创建内容数据库和网站集。我们可以使用SPUser还是有其他方法可以做到这一点吗?能否请您提供我可以解决上述问题的任何代码或链接?

1 个答案:

答案 0 :(得分:2)

听起来您可能需要使用SPSecurity.RunWithElevatedPrivleges。这将允许您运行代码,就像您是服务器场管理员应用程序池标识帐户一样。要小心,因为它为用户提供了运行代码 full 更高的访问权限,但听起来这就是你想要的。

SPSecurity.RunWithElevatedPrivileges(delegate()
{
    using (SPSite topSite = new SPSite("URL_OF_YOUR_SITE_COLLECTION"))
    {
       //Any code you run here would run with the permissions of the application pool identity
    }
});
相关问题