Tuesday, 20 March 2018

Enable Anonymous access to search results.

I am working on one task to display list items using a display template to anonymous users. I have also made the managed search property safe for the anonymous user, but it is still not working for the anonymous user.

Out-of-the-box, the search results webpart (via display template) will try to display data to users (anonymous and authenticated users); authenticated users will see results, while anonymous users will see no results.

Here I will use the PowerShell script to allow list-level anonymous access.

#
# Description:
# List-Level Permission settings to enable anonymous access.
#
# Created Date:
# v1.0 - 20-03-2018
#
# Author:
# Vikas Bansal
#
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$listName = "TestList"
$web = Get-SPWeb “http://sp2013.com”
$list = $web.Lists.TryGetList($listName)
if($list -ne $null)
{
Write-Host $listName " exists on the" $web.Title at URL $web.Url -ForegroundColor DarkBlue -BackgroundColor Yellow
if(!$list.HasUniqueRoleAssignments) {
$list.BreakRoleInheritance($true)
}
#$list.AnonymousPermMask = $list.AnonymousPermMask -bor ([int][Microsoft.SharePoint.SPBasePermissions]::ViewFormPages) #binary or adding the permissions
$list.AnonymousPermMask64= $list.AnonymousPermMask64 -bor ([int][Microsoft.SharePoint.SPBasePermissions]::AnonymousSearchAccessList) #binary or adding the permissions
$list.Update()
Write-Host $listName " permission is changed for anonymous user" $web.Title at URL $web.Url -ForegroundColor DarkGreen -BackgroundColor White
}
else
{
Write-Host $listName " not exists on the" $web.Title at URL $web.Url -ForegroundColor Yellow -BackgroundColor Red
}


The commented AnonymousPermMask property, according to MSDN, is deprecated and you need to use AnonymousPermMask64.



Instead of ViewFormPages, we need to use AnonymousSearchAccessList, which is described as "Make content of a list or document library retrieveable for anonymous users through SharePoint search. The list permissions in the site do not change".

Then run a full search crawl.


🚀 "Happy Coding" 🚀

1 comment:

  1. Great and that i have a nifty provide: How Many Houses Have Been Renovated On Hometown average remodel cost

    ReplyDelete