Hello Guys. I am back with new blog that is more relevant to things we need to take care when we enable anonymous search on our SharePoint site. In my current implementations I came through many various scenarios where SharePoint site will be available publicly.
Enable anonymous user search rest API please follow below steps:
So here I am sharing my experience when we are enabling anonymous access to SharePoint site.
To enable rest query on List using anonymous user do execute bellow script in SharePoint Management Shell:
$site = Get-SPSite <<your anonymous site collection url>>$site.UpdateClientObjectModelUseRemoteAPIsPermissionSetting($false)Reference URL : https://blogs.msdn.microsoft.com/kaevans/2013/10/24/what-every-developer-needs-to-know-about-sharepoint-apps-csom-and-anonymous-publishing-sites/
To enable Get Items in SharePoint list for anonymous user do execute bellow script in SharePoint Management Shell:
$web = Get-SPWebApplication -Identity <<your anonymous site collection url>>Reference URL : https://sharepointinaction.wordpress.com/2013/07/16/error-the-method-getitems-of-the-type-list-with-id-listss-guid-is-blocked-by-the-administrator-on-the-server/
$web.ClientCallableSettings.AnonymousRestrictedTypes.Remove([Microsoft.SharePoint.SPList],"GetItems")$web.Update()
Enable anonymous user search rest API please follow below steps:
- Add your anonymous extended root site URL to content source.
- Put content source on full crawl to which you have added your anonymous site url
- Run below powershell commands
- (Get-SPFarm).Id
- (Get-SPSite <your root site collection url>).Id
- (Get-SPWeb <your root site collection url>).Id
- Create new blank text file using notepad named as queryparametertemplate.xml (please use notepad only because another editor may add some unwanted format to your file)
- Copy/Paste below xml to newly created xml file in above step and replace guid with higlighted text in file:
<QueryPropertiesTemplate xmlns="http://www.microsoft.com/sharepoint/search/KnownTypes/2008/08" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<QueryProperties i:type="KeywordQueryProperties">
<EnableStemming>true</EnableStemming>
<FarmId>FARMID from command 1</FarmId>
<IgnoreAllNoiseQuery>true</IgnoreAllNoiseQuery>
<KeywordInclusion>AllKeywords</KeywordInclusion>
<SiteId>SITEID from command 2</SiteId>
<SummaryLength>180</SummaryLength>
<TrimDuplicates>true</TrimDuplicates>
<WcfTimeout>120000</WcfTimeout>
<WebId>WEBID from command 3</WebId>
<Properties xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<a:KeyValueOfstringanyType>
<a:Key>_IsEntSearchLicensed</a:Key>
<a:Value i:type="b:boolean" xmlns:b="http://www.w3.org/2001/XMLSchema">true</a:Value>
</a:KeyValueOfstringanyType>
<a:KeyValueOfstringanyType>
<a:Key>EnableSorting</a:Key>
<a:Value i:type="b:boolean" xmlns:b="http://www.w3.org/2001/XMLSchema">true</a:Value>
</a:KeyValueOfstringanyType>
<a:KeyValueOfstringanyType>
<a:Key>MaxKeywordQueryTextLength</a:Key>
<a:Value i:type="b:int" xmlns:b="http://www.w3.org/2001/XMLSchema">4096</a:Value>
</a:KeyValueOfstringanyType>
<a:KeyValueOfstringanyType>
<a:Key>TryCache</a:Key>
<a:Value i:type="b:boolean" xmlns:b="http://www.w3.org/2001/XMLSchema">true</a:Value>
</a:KeyValueOfstringanyType>
</Properties>
<PropertiesContractVersion>15.0.0.0</PropertiesContractVersion>
<EnableFQL>false</EnableFQL>
<EnableSpellcheck>Suggest</EnableSpellcheck>
<EnableUrlSmashing>true</EnableUrlSmashing>
<IsCachable>false</IsCachable>
<MaxShallowRefinementHits>100</MaxShallowRefinementHits>
<MaxSummaryLength>185</MaxSummaryLength>
<MaxUrlLength>2048</MaxUrlLength>
<SimilarType>None</SimilarType>
<SortSimilar>true</SortSimilar>
<TrimDuplicatesIncludeId>0</TrimDuplicatesIncludeId>
<TrimDuplicatesKeepCount>1</TrimDuplicatesKeepCount>
</QueryProperties>
<WhiteList xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<a:string>RowLimit</a:string>
<a:string>SortList</a:string>
<a:string>StartRow</a:string>
<a:string>RefinementFilters</a:string>
<a:string>Culture</a:string>
<a:string>RankingModelId</a:string>
<a:string>TrimDuplicatesIncludeId</a:string>
<a:string>ReorderingRules</a:string>
<a:string>EnableQueryRules</a:string>
<a:string>HiddenConstraints</a:string>
<a:string>QueryText</a:string>
<a:string>QueryTemplate</a:string>
<a:string>SelectProperties</a:string>
<a:string>SourceID</a:string>
</WhiteList>
</QueryPropertiesTemplate>
- Go to your SharePoint root Site collection > Site Contents
- Create new document library named QueryPropertiesTemplate
- Upload your newly created xml queryparametertemplate.xml in above step into QueryPropertiesTemplate
- Go to your anonymous site and add &QueryTemplatePropertiesUrl='spfile://webroot/queryparametertemplate.xml' at end of your search query for REST
- If you are using SharePoint variation sites in your implementation then at each variation site create new document library QueryPropertiesTemplate and upload QueryPropertiesTemplate into it.
That's it from my sides folks. Will update blog if I come through any other possibilities.
Thanks !!!