After creating an ASP.NET Web Application (.NET Framework) project in Visual Studio 2022 and adding a web service to it, everything seemed to work fine when testing the web service call on Local IIS. However, things took a different turn when I tried running the projects in a container (Windows containers). What could be causing this issue? The error message that pops up is as follows: Access to XMLHttpRequest at 'http://localhost:5002/WebService.asmx/HelloWorld' from origin 'http://172.17.78.68' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Below is a snippet of my docker-compose.yml file:
version: '3.4'
services:
saview:
image: ${DOCKER_REGISTRY-}saview
build:
context: .\SAview
dockerfile: Dockerfile
ports:
- 5001:80
links:
- saviewweb
depends_on:
- "saviewweb"
networks:
- mynetwork
saviewweb:
image: ${DOCKER_REGISTRY-}saviewweb
build:
context: .\SaviewWeb
dockerfile: Dockerfile
ports:
- 5002:80
networks:
- mynetwork
networks:
mynetwork:
driver: nat
This is how I am currently making a request using JavaScript:
function Web(arg, url ) {
var result;
$.ajax(
{
type: 'POST', url: url, data: JSON.stringify(arg),
dataType: 'json',
contentType: "application/json; charset=utf-8", async: false, success: function (res) {
result = res;
}
, error: function (a1, a2, a3) {
result =
{
d: "_Error_" + a1 + " " + a2 + " " + a3
};
} //-
});
if (result.d == null)
return null;
if (result.d.indexOf != undefined && result.d.indexOf("_Error_") !== -1) {
alert(result.d);
return null;
}
return result;
}
Web({}, "http://localhost:5002/WebService.asmx/HelloWorld" );