question

AkshayKamble avatar image
6 Votes"
AkshayKamble asked AkshayKamble commented

SharePoint Server 2019 Modern site search does not work for anonymous user.

Anonymous users cannot view search results on SharePoint server 2019 Modern communication site. It gets 500 error when it tries to query the search api as seen in the console.
I would really appreciate help in this regard.
I have been banging my head against wall over this.
Thanks a lot.
Please let me know if any details are needed.

Update: If the anonymous user searches from osssearchresults.aspx, it shows them results but not from modern search control/page.

111552-screenshot-2021-07-03-152904.png



office-sharepoint-server-administrationoffice-sharepoint-server-search-itpro
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@trevorseward @StefanGossner-MSFT Do you have any information about this issue?

0 Votes 0 ·

1 Answer

CaseyYangMSFT-4714 avatar image
1 Vote"
CaseyYangMSFT-4714 answered AkshayKamble commented

Hi @AkshayKamble

Per my research, you could try to create a queryparametertemplate.xml file to enable anonymous Search REST queries.

1.Add a new document library named QueryPropertiesTemplate to the publishing site.
2.Create an XML file named queryparametertemplate.xml
XML code:

 <QueryPropertiesTemplate xmlns="https://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</FarmId>
     <IgnoreAllNoiseQuery>true</IgnoreAllNoiseQuery>
     <KeywordInclusion>AllKeywords</KeywordInclusion>
     <SiteId>SiteID</SiteId>
     <SummaryLength>180</SummaryLength>
     <TrimDuplicates>true</TrimDuplicates>
     <WcfTimeout>120000</WcfTimeout>
     <WebId>WebID</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>
   </WhiteList>
 </QueryPropertiesTemplate>

Note: Remember to update the SiteId, FarmId, and WebId elements with the values for your farm, website and publishing site collection.
3.Save queryparametertemplate.xml to the QueryPropertiesTemplate document library.
4.Add the QueryTemplatePropertiesUrl parameter to your Search REST call, specifying spfile://webroot/queryparametertemplate.xml as the value.

For Reference:
SharePoint Search REST API overview


If an Answer is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@CaseyYangMSFT-4714. Thanks for your response. Yes, I implemented this approach and it works well so far. But I did not find it mentioned in the docs if this technique applies to SP Sever 2019 the way it says about SP Online. So, I was not quite sure if we can use it for our customer's production site. Anyway, essentially you're saying that I can go ahead and continue using it even though docs explicitly don't mention it, and there won't be any issues, right?

0 Votes 0 ·

Hi @AkshayKamble

Thank you for reply. Per my knowledge, If you just edit search rest api like this there won't be any issues.

1 Vote 1 ·

Hi @CaseyYangMSFT-4714, thank you very much. I will continue with this approach. This API will keep working in future also for SP server 2019 as it's working now, correct? I mean, there won't be any discontinuation in the availability/support of this API in near future, will there?

0 Votes 0 ·
Show more comments