我正在爲他登錄的用戶迭代當前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);
}
}
}
}
}
});
它仍在用戶的安全上下文中運行。 – James123 2011-03-21 15:59:38
嘗試只用最後一次使用內部運行與提升的權限 – 2011-03-21 16:13:51
這就是我說的,最後使用的是內部高架privieges。 – James123 2011-03-21 16:22:26