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.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);
}
}
}
}
}
});