I followed this article to display sub-sites on site collection's home page. I works fine when user have contribute access. But user with read or view only gets Access Denied. What are my options so I can be viewable for everyone with any permission(s).


3 Answers 3


It worked after i used SPSecurity.RunWithElevatedPrivileges(delegate() to wrap it around.


One thing to check before resorting to runwithelevatedprivileges is that the page you're showing to the user is both 'published' and 'approved' otherwise strange things can happen with permissions

  • Good point HC. I will go ahead and adhere with Anders solution and see how it plays after launching to dev and test. Thanks HC
    – Bob Dinero
    Nov 10, 2010 at 14:06

A couple of things to note:

When you wrap your code with RWEP you will override the normal security trimming, and hence when users click the sites they are not allowed to see (this is why the code fails with access denied, since you are not allowed to see all elements in the SPWebCollection). A better alternative is to use SPWeb.GetSubWebForCurrentUser.

Also the code you point to have memory leak issues: you should dispose SPSite and SPWeb controls created by yourself. Find a good guidance here on how to correctly dispose webs and sites.

Also beware that if you have alot of sub sites touching SPWebCollection (rootSite.Webs) could be an expensive operation.

  • Thanks Anders. I implemented the change in the code but haven't deployed to dev or test to see whether is going to work or not.
    – Bob Dinero
    Nov 10, 2010 at 14:05
  • im not saying it doesnt work, im saying your production environment will leak SPRequest objects until memory is full and it will then recycle application pool, slowing your site down as it goes. Also it is unnecessary to use RWEP as you have a method for what you want to achieve (GetSubWebForCurrentUser) Nov 10, 2010 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.