开发者

Access denied error while iterating Mysites site collection?

开发者 https://www.devze.com 2023-02-18 14:51 出处:网络
I was iterating current sharepoint site collection for the user which he logged into, and displaying sites names which he has read and contribute permission to sites and this is working fine.

I was iterating current sharepoint site collection for the user which he logged into, and displaying sites names which he has read and contribute permission to sites and this is working fine.

At the same time I have to iterate Mysites site collection where has read and contribute permission. When I do foreach (SPWeb jweb in esite.AllWebs) in Mysites site collection sub sites. It is throwing an error "ACCESS DENIED".

But when I typed url in on browser he can see those sites?. I added code in SPSecurity.RunWithElevatedPrivileges still unable to access those site. This _layout folder page and I written code in aspx page only.

How to resolve this?

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.GetSubwebsForCurrent开发者_如何学GoUser().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);
              }
            }
          }
        }
      }
    });


According to your comments, RunWithElevatedPrivileges is running in the identity of the Application Pool on http://committees.test.com, but is trying to access a site collection on http://mysitesdev.test.com. Are both web applications using the same Application Pool identity? Unless the Application Pool identity on http://committees.test.com has permissions on http://mysitesdev.test.com/groups/grp, I would expect an Access Denied error.


You are running your for each outside the run with elevated privileges, so it is still running in the security context of the user.

0

精彩评论

暂无评论...
验证码 换一张
取 消