We're developing a public facing SharePoint site so it have anonymous access. To be able to run custom web parts that access lists/libraries we need to run with elevated privileges which works fine, no problem.
However, we have custom user control that displays the current sites sub sites and in the code we use .Webs which seems to be a problem (we get prompted for credentials on the page and when we debug).
private void LoadSubsites()
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPWeb web = SPContext.Current.Site.OpenWeb(SPContext.Current.Web.ServerRelativeUrl))
{
var sites = web.Webs.Select(w => new { Title = w.Title, Url = w.Url });
if (sites != null)
{
rptSubsites.DataSource = sites;
rptSubsites.DataBind();
}
}
});
}
What should I do to enable anonymous users to access pages with this user control?
Thanks in advance
using (SPSite site = new SPSite(SPContext.Current.Site.ID)) { using (SPWeb web = site.OpenWeb(SPContext.Current.Web.ID)) { ... } }
?