sharepoint 一个有用的方法SPSecurity.RunWithElevatedPrivileges(delegate(){})

SPSecurity.RunWithElevatedPrivileges( delegate()  {
  // 此处显示的是要在提升权限的情况下运行的代码。
  // 该代码段在 SHAREPOINT/SYSTEM 帐户下运行。
});

//例

SPSecurity.RunWithElevatedPrivileges(
delegate()
{
using (SPSite ElevatedsiteColl = new SPSite("http://xxxx:xx"))//获得spsite;
{
using (SPWeb ElevatedSite = ElevatedsiteColl.OpenWeb())//获得spweb;
{
string SiteCollectionOwner = ElevatedsiteColl.Owner.Name;
string Visits = ElevatedsiteColl.Usage.Visits.ToString();
string RootAuditEntries =ElevatedSite.RootFolder.Audit.GetEntries().Count.ToString();
}
}
});

你可能感兴趣的:(SharePoint)