Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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).

http://social.msdn.microsoft.com/Forums/en-US/isv/thread/0eedc84e-3bbd-433d-81ba-db1a9e9322ef

share|improve this question
add comment

3 Answers

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

share|improve this answer
    
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 '10 at 14:06
add comment
up vote 1 down vote accepted

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

share|improve this answer
add comment

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.

share|improve this answer
    
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 '10 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) –  Anders Rask Nov 10 '10 at 15:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.