2011-03-21 61 views
0

我正在爲他登錄的用戶迭代當前SharePoint站點集合,並顯示他已閱讀的網站名稱併爲網站提供許可,並且此工作正常。
同時,我必須迭代已閱讀並貢獻權限的Mysites網站集。當我在Mysites網站收集子站點中進行foreach(esite.AllWebs中的SPWeb jweb)時。這是拋出一個錯誤「訪問被拒絕」。迭代Mysites網站集時訪問被拒絕錯誤?

但是,當我在瀏覽器中鍵入url時,他可以看到這些網站?我在SPSecurity.RunWithElevatedPrivileges中添加了代碼,但仍無法訪問這些網站。這_layout文件夾頁面,我只寫在aspx頁面的代碼。

如何解決這個問題?

SPSite site = SPContext.Current.Web.Site; // http://committees.test.com 
SPUser user = SPContext.Current.Web.CurrentUser; 
SPSecurity.RunWithElevatedPrivileges(delegate() 
{ 
    using (SPSite esite = new SPSite(site.ID)) 
    { 
    Control cont5 = this.LoadControl("/_CONTROLTEMPLATES/ALERTUC/uc5.ascx"); 
    cont5.ID = "GLOBE"; 
    RadioButtonList glbrbl = (RadioButtonList)cont5.FindControl("RBList5"); 

    try 
    { 
      glbrbl.SelectedValue = user.Notes.ToString(); 
    } 
    catch (Exception) { } 
    GlobalPnl.Controls.Add(cont5); 
    foreach (SPWeb jweb in esite.AllWebs) 
    { 
      if (!jweb.IsRootWeb) 
      { 
      if (jweb.GetSubwebsForCurrentUser().Count != 0) 
      { 
       if (jweb.ParentWeb.ID == jweb.Site.RootWeb.ID) 
       { 
       getsubweb(jweb, Panel1, user); 
       } 
      } 
      } 
     } 

    }//using   
using (SPSite esite = new SPSite("http://mysitesdev.test.com/groups/grp")) 
{ 
     foreach (SPWeb jweb in esite.AllWebs) //**Access Denied** 
     { 
      if (!jweb.IsRootWeb) 
      { 
      if (jweb.GetSubwebsForCurrentUser().Count != 0) 
      { 
       if (jweb.ParentWeb.ID == jweb.Site.RootWeb.ID) 
       { 
       getsubweb(jweb, Panel1, user); 
       } 
      } 
      } 
     } 
     } 
    }); 

回答

1

根據您的意見,RunWithElevatedPrivileges以http://committees.test.com的應用程序池標識運行,但試圖訪問http://mysitesdev.test.com上的網站集。兩個Web應用程序是否使用相同的應用程序池標識?除非http://committees.test.com上的應用程序池標識擁有http://mysitesdev.test.com/groups/grp的權限,否則我會期待Access Denied錯誤。

0

您正在運行的每個外部運行提升特權,所以它仍然在用戶的安全上下文中運行。

+0

它仍在用戶的安全上下文中運行。 – James123 2011-03-21 15:59:38

+0

嘗試只用最後一次使用內部運行與提升的權限 – 2011-03-21 16:13:51

+0

這就是我說的,最後使用的是內部高架privieges。 – James123 2011-03-21 16:22:26