Hi,
I am trying to set anonymous access for a document library(pages library) pragmatically in sharepoint 2013. I used the below code to set anonymous access
public void SetAnonymousPermissionToSPListArray(SPWeb web, SPList list){
try
{
//Execute the statements with FullControl rights
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite elevatedSite = new SPSite(web.Site.ID))
{
SPWeb elevatedWeb = elevatedSite.OpenWeb(web.ID);
elevatedWeb.AllowUnsafeUpdates = true;
//Set anonymous access for the current site
if (web.AnonymousState != SPWeb.WebAnonymousState.On)
{
web.AnonymousState = SPWeb.WebAnonymousState.On;
web.AnonymousPermMask64 = SPBasePermissions.ViewListItems | SPBasePermissions.ViewVersions | SPBasePermissions.Open | SPBasePermissions.ViewPages;
web.Update();
}
list.BreakRoleInheritance(true);
list.AllowEveryoneViewItems = true;
list.AnonymousPermMask64 = SPBasePermissions.ViewListItems;
list.Update();
}
});
}
catch (Exception ex)
{
throw ex;
}
}
The document library was set with anonymous acess .But when i try to access the pages inside that library from my extranet site,it is redirecting to login page.But already i have the create webapplication with anonymous access.
If i do this through UI, i am able to access the anonymous page. what i am missing in the code.Kindly help me in this.
Thanks & Regards,
J.Akila