Anonymous Access and Publishing Web Pages List
As You know, using PublishingWeb.GetPublishingWeb(web) method causes Access Denied exception for anonymous users. You will also get the same exception if you try to access the PublishingWeb.GetPagesListId(web) or PublishingWeb.GetPagesListName(web) methods.
There are solutions here and here and in many other blogs. These solutions use SPSecurity.RunWithElevatedPrivileges, but that’s not ideal solution for anonymous sites.
So how to get pages list from a web, if you don’t even know if the web is publishing site and you are not able to use PublishingWeb.IsPublishingWeb(web)?
Heres yet another solution. Open the web you want to check if it is a publishing site and try to get the pages list using TryGetList method with the right localized pages list name. You will get the localized name from cmscore.resx file using SPUtility.GetLocalizedString method with resource key “List_Pages_UrlName”.
string.Format("$Resources:{0}", "List_Pages_UrlName"),
"cmscore", web.Language));
if (pages != null)
{
// do the do
}
It all gets interesting, if the site is not publishing web, but still contain a list called “Pages”. Then You might want to check another things from returned list, not just if it’s null like in the snippet above.
***********************************************
Jerry Seinfeld: Why not? We’re neighbors. What’s mine is yours.
Cosmo Kramer: [leaning against the door-frame and looking around in wonder] Really?
***********************************************
Popularity: 1% [?]