When connecting a website via the Sitecore Federated Experience Manager I was prompted to add a script to the destination site:
<script src="//linkedwebsite.com/bundle/beacon"></script>
After adding the script, I receiving the following error on all the pages the script was added to:
XMLHttpRequest cannot load http://mywebsite.com/sitecore/api/ssc/Beacon/Service/beacon/trackPageVisit/?co…=&sessionId=&page=http%3A%2F%2Flinkedwebsite.com%2F&referrer=&rt=1501507187250. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://linkedwebsite.com' is therefore not allowed access.
I found this Sitecore article which detailed two possible sources of the error:
https://kb.sitecore.net/articles/150778
The first was EnableCors()
was not being called before GlobalConfiguration.Configure(...)
in a custom pipeline. I noticed that we had in fact called GlobalConfiguration.Configure(...)
without calling EnableCors()
so I added the EnableCors
call before the Configure call, restarted IIS, but continued to receive the same error.
The next possible source of error was the use of IIS redirects. The site I'm working on makes extensive use of these redirects so it was tough to tell if this configuration was causing a problem. To test, I removed all IIS redirects from the site but still received the XMLHttpRequest
error.
The linked website as well as my Sitecore website are being run on my local IIS server. I searched through our source code and found no additional places that GlobalConfiguration.Configure(...)
is called. I also tracked the GlobalConfiguration.Configuration
variable in the debugger and it appears that the changes EnableCors()
makes to the object remain throughout the Sitecore session (I set a breakpoint in one of the controller renderings to test this). Any ideas on additional steps I could take to test or resolve this error? Thank you for your time and help!
EDIT 1:
Here is the response header when I hit the FXM API at the error location and the JSON that is returned:
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json
Expires: -1
Server: Microsoft-IIS/10.0
Set-Cookie: sc_expview=0; path=/
P3P: CP="CURa ADMa DEVa TAIi PSAi PSDi IVAi IVDi CONi HISa TELi OUR IND DSP CAO COR"
Set-Cookie: SC_ANALYTICS_GLOBAL_COOKIE=7730eccae6524d60adcc7b822c28f8a6|True; domain=.mywebsite.com; expires=Sat, 31-Jul-2027 15:18:10 GMT; path=/; HttpOnly
X-UA-Compatible: IE=edge
Date: Mon, 31 Jul 2017 15:18:10 GMT
Content-Length: 198
{"ContactId":"7730eccae6524d60adcc7b822c28f8a6|True","SessionId":"yvcffcceb1j4asjxsv3j2zfj","ContactExpires":"2019-07-31T09:14:10.648051","SessionPath":"/","ElementMatches":[],"Id":null,"Url":null}
EDIT 2:
I've removed all custom routing relevant to the api path, for example:
RouteTable.Routes.MapHttpRoute(
"DefaultApiRoute",
"api/{controller}/{action}");
However, I continued to experience the same error.
http://mywebsite.com/sitecore/api
one) with Postman/curl/etc. and add what the response headers are?RouteTable.Routes.MapHttpRoute( "DefaultApiRoute", "api/{controller}/{action}");