I have SharePoint 2019 on premise communication site which manages the public facing site. My search is working on on-premise site but it shows the error message which says
Access to XMLHttpRequest at 'On premise site' from origin 'public facing site' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I assume that I need to put the rules and add allow content origin policy in the web.config file inside the <system.webServer>. What and how should I add the allow customHeaders? The existing customHeaders
<add name="X-Content-Type-Options" value="nosniff" />
<add name="X-MS-InvokeApp" value="1; RequireReadOnly" />
Should I delete it? I tried adding the following but does not work for me.
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" />
<add name="Access-Control-Allow-Methods" value="POST,GET,OPTIONS,PUT,DELETE" />
</customHeaders>
</httpProtocol>
<rewrite>
<outboundRules>
<clear />
<rule name="AddCrossDomainHeader">
<match serverVariable="RESPONSE_Access_Control_Allow_Origin" pattern=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<add input="{HTTP_ORIGIN}" pattern="(http(s)?://((.+\.)?domain1\.com|(.+\.)?domain2\.com|(.+\.)?domain3\.com))" />
</conditions>
<action type="Rewrite" value="{C:0}" />
</rule>
</outboundRules>
</rewrite>
</system.webServer>