I have a custom webservice hosted in SharePoint. Within this service, I need to at times look up sites by id. Despite running code in an SPSecurity.RunWithElevatedPriviledges block, I still get Access exceptions for non-admin users when trying to look up a site by id.
From what I've read, I may be able to get around this problem by opening the site collection using a User token for an admin account. My problem is, how do I get a user token for an admin account?
Any help is greatly appreciated.
//Putting this inside RunWithElevatedPrivileges causes it to fail
var siteCollection = new SPSite(SITE_COLLECTION_URL);
//This throws for non-admins, regardless of being in a RunWithElevatedPriviledges block
var web = siteCollection.AllWebs[webId]);