views:

10

answers:

1

I'm trying to list all the links on all the SharePoint web sites (parent and sub). When I'm logged in as the admin user it works just fine. However, when I sign on as a normal user I get an access denied error. And the error is thrown when I check the count property of the SPWebCollection.

SPSite oSiteCollection = SPContext.Current.Site;
SPWebCollection collWebsite = oSiteCollection.AllWebs;

StringBuilder labelText = new StringBuilder();

for (int i = 0; i < collWebsite.Count; i++) // <---- Access denied on count
{ // get links }

I tried adding giving my normal user full site control and I still received the access denied error. Any idea what access rule is being checked when accessing the count property?

A: 

You can try and use your application pool's account using the RunWithElevatedPrivileges method on SPSecurity.

SPSecurity.RunWithElevatedPrivileges(delegate()
{
   SPSite oSiteCollection = SPContext.Current.Site;
   SPWebCollection collWebsite = oSiteCollection.AllWebs;

   StringBuilder labelText = new StringBuilder();

   for (int i = 0; i < collWebsite.Count; i++) // <---- Access denied on count
   { // get links }
});
Steve Danner
Look like there is a security action of demand on ObjectModel=trueCount property of SPWebCollection: public override int Count { [SharePointPermission(SecurityAction.Demand, ObjectModel=true)] get { this.EnsureWebsData(); return this.m_strWebNames.Length; } }Any idea where that permission is configured?
Dave
I get the same result if I use RunWithElevatedPrivileges
Dave

related questions