Пример #1
0
 public static void AsUser(string UserLogin, RunManageSiteWithAdminDelegate myDelegate)
 {
     SPUser user = SPContext.Current.Web.SiteUsers[UserLogin];
     using (SPSite site = new SPSite(currentSiteUrl, user.UserToken))
     {
         site.AllowUnsafeUpdates = true;
         using (SPWeb web = site.OpenWeb(currentSiteUrl))
         {
             web.AllowUnsafeUpdates = true;
             myDelegate.Invoke(site, web);
         }
     }
 }
Пример #2
0
        //public static void AsUserByUrl(string Url, string UserLogin, RunManageSiteWithAdminDelegate myDelegate)
        //{

        //    SPSecurity.RunWithElevatedPrivileges(delegate()
        //    {
        //        SPUser user = SPContext.Current.Web.SiteUsers[UserLogin];
        //        using (SPSite site = new SPSite(currentSiteUrl))
        //        {
        //            site.AllowUnsafeUpdates = true;
        //            using (SPWeb web = site.OpenWeb(Url))
        //            {
        //                web.AllowUnsafeUpdates = true;
        //                myDelegate.Invoke(site, web);
        //            }
        //        }
        //    });
        //}

        public static void RootSiteByUrl(string Url, RunManageSiteWithAdminDelegate myDelegate)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(Url))
                {
                    site.AllowUnsafeUpdates = true;
                    using (SPWeb web = site.RootWeb)
                    {
                        web.AllowUnsafeUpdates = true;
                        myDelegate.Invoke(site, web);
                    }
                }
            });
        }
Пример #3
0
 public static void Privileges(RunManageSiteWithAdminDelegate myDelegate)
 {
     SPSecurity.RunWithElevatedPrivileges(delegate()
     {
         using (SPSite site = new SPSite(currentSiteUrl))
         {
             site.AllowUnsafeUpdates = true;
             using (SPWeb web = site.OpenWeb(currentSiteUrl))
             {
                 web.AllowUnsafeUpdates = true;
                 myDelegate.Invoke(site, web);
             }
         }
     });
 }