Spweb web = spcontrol. getcontextweb (context );
// Obtain all sub-sites under the current site
Spwebcollection subwebs = web. webs;
Foreach (spweb WB in subwebs)
{....}
End
The current user is an ordinary reader !! You can view the subwebsite of each subwebsite...
Result: failed!
Spsecurity. runwithelevatedprivileges (delegate
{
Spweb web = spcontrol. getcontextweb (context );
// Obtain all sub-sites under the current site
Spwebcollection subwebs = web. webs;
Foreach (spweb WB in subwebs)
{....}
});
Still failed. Failure location: Web. webs;
Tip: no permission. Verification Failed!
Last modified version:
Spsecurity. runwithelevatedprivileges (delegate
{
Using (spweb WB = new spsite (Web. Site. ID). openweb (Web. ID ))
{
// Obtain all sub-sites under the current site
Spwebcollection subwebcol = WB. webs;
For (INT I = 0; I <subwebcol. Count; I ++)
{
If (I <subwebupcount)
{
If (subwebcol [I]. doesuserhavepermissions (spbasepermissions. Open ))
{
Subleftnav (subwebcol [I], "navlevel2", "navitem", Web. ID );
Subwebcol [I]. Dispose ();
}
}
}
}
});
Result: Successful!
To sum up, You must create a new contex context under the elevation of permission and then do what you want, as shown in the above simhei. The second one is acceptable!
Emotion: moss permission control is huge!