
I have tried many ways to resolve the CORS issue by following several blogs but was unsuccessful. Please suggest if you find any answer.
The Issue is when i upgraded from IE 11 to Edge by Chromium.
I am working on Dynamics 365 CRM Onpremise. We host external web application in CRM. Both will be on same server but different port. When I try to access external Web pages, it asks for authentication and everything is good. But when I make XmlHttpRequest to call json functions in my external web project, I get this error:
"Access to XMLHttpRequest at 'http://{server}:{port}/{org}/{controller}/{function_name}' from origin 'http://{server}' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status."
I tried to add site in trusted sites n IE and import settings on EDGE from Internet Explorer. This did not fix the issue.
I get the same issue on chrome as well. I did not get this issue with Internet Explorer.
Sample Call in javascript on CRM: CRM and web application is on same server but different port. In this example, I am calling a method in my web project to do something on form save.
var req = new XMLHttpRequest();
req.open("POST", encodeURI("http://{server}:{port}/{org}/{controller}/{function_name}"), false);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
var data = JSON.stringify({
id: someguid
});
req.onreadystatechange = function () {
if (this.readyState == 4) {
req.onreadystatechange = null;
if (this.status == 200) {
var result = JSON.parse(req.response);
} else {
var error = JSON.parse(this.response).error;
console.log(error);
}
}
};
req.send(data);
I have the same CORS issue with Iframe as well. I have an Iframe on the CRM form. It points to a web page on my web project. Note this Iframe does not point to html webresource. On load of CRM form, I load the IFRAME with webpage which is on external port. So, here I will be asked for Authentication from web project and IFRAME loads fine.
But when CRM form tries to access any field on IFRAM using: iFrame.getObject().contentWindow.document.getElementById does not work.
And when IFRAME tries to access Parent form by using: window.parent.Xrm.Page, this gives me CORS issue.
I followed ASP.net web application Enable CORS by giving this in my web.config
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Headers" value="accept, content-type" />
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="POST, GET, OPTIONS" />
</customHeaders>
</httpProtocol>
</system.webServer>