Moss permissions are well controlled and powerful.

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.