How to personalize the farm administrator in the server object model?

We use SharePoint Foundation 2010. We create a content database and site collection using the server object model. We have over 1000 users in SharePoint. Since creating a content database and creating a site collection is an administrative task, only the admin administrator can do this. In our case, any user should be able to create a content database and site collection using the farm administrator account. Can we use SPUser or is there another way to do this? Can you provide me with any code or link through which I can solve the above problem?

+5
source share
1 answer

It looks like you might need SPSecurity.RunWithElevatedPrivleges . This allows you to run the code as if you were a farm administrator.application pool account. Be careful because it gives the user faster access to , , , .

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
    }
});
+2
source

All Articles