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 have this code:

SPWeb web = SPContext.Current.Web;

string dummy = String.Empty;

SPWeb subwebByName = web.Webs["Example"];
dummy = subwebByName.Name;

Guid subwebId = new Guid("{5fad4b3b-3124-47d1-b268-86e322e6f2d1}");
SPWeb subwebById = web.Webs[subwebId];
dummy = subwebById.Name;

If I run this code under a user who is in the owner group it works fine.

But if I have a user who is in the visitor group the line web.Webs[subwebId] generates a ThreadAbortException and I get redirected to a page that says "Error: Access denied". The access by name works.

So why does SPWebCollection[Guid] needs more permissions than SPWebCollection[string]? And where is this documented? ;)

share|improve this question

1 Answer 1

.NET Reflector might be useful for solving these problems.

public SPWeb this[Guid id] calls private method SPWeb.EnsureWebsData(). This method then calls SPRequest.GetSubwebsFiltered() or SPRequest.GetSubwebs(). Those methods may throw access denied exceptions.

For unknown reasons, public SPWeb this[string name] does not call EnsureWebsData().

Probably you user does not have access on all subwebs and there it fails. Or there is some other reason. Those methods work differently, so different results are expected. I would just stick with what works.

share|improve this answer
1  
I would suggest ILSpy as an alternative, but the current release doesn't seem to show up property indexers yet, which is a shame. –  James Love Jul 17 '11 at 19:02

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.