I have an asp.net mvc5 (with Angular) website installed in IIS on a Win 2008 R2 Ent server, and everything runs fine while running the site on the server itself.
As soon as we access the site from outside the server, I'm getting CORS related errors :
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost/api/init?space=razor_RAGE&environment=razor_RAGE&clariteConfig=E:\razor_RAGE\master\bin\clarite_config.xml. This can be fixed by moving the resource to the same domain or enabling CORS.
I thought the solution was to add the proper headers to the http request :
'Access-Control-Allow-Origin': 'true'
however it doesn't seem to be solving the CORS issues.
Here's an example of a request I'm making from JavaScript (all good on the server, but will not work outside the server) :
this.getRazorInitParams = function () {
var deferred = $q.defer();
deferred.notify("Getting init parameters...");
var razorEnvParams = [];
$http({
method: 'GET',
encoding: 'JSON',
headers: {
'Access-Control-Allow-Origin': 'true'
},
url: 'breeze/Rage/GetRazorEnv'
}).success(function (data, status, headers, config) {
razorEnvParams = data;
deferred.resolve(razorEnvParams);
}).error(function (data, status, headers, config) {
console.log("Error in userContext.js, getRazorInitParams " + status);
});
return deferred.promise;
}
Here's a snipet from the c# api layer :
public class initController : ApiController
{
public HttpResponseMessage Get()
{
// space, env, dom, cConf vars all defined here..
string resp = DynAggrClientAPI.initApp( space, env, dom, cConf );
var response = Request.CreateResponse(HttpStatusCode.OK);
response.Content = new StringContent(resp, Encoding.UTF8, "application/json");
return response;
}
}
I'm searching around for the right solution. Is there anything I'm missing here ?
thanks in advance,
Bob