OK, I have 3 servers that need to communicate together for a GET request. But I keep getting the origin is missing error, I can see the information that I want to receive in postman (so I know that my url's and passing on information works).
JQuery
function GetData(nummer, insz) {
showLoader(true);
var func = function (host) {
$.ajax({
type: "GET",
url: host + "/api/GetList/" + number + "/" + version + "/" + typeId + "/" + extraPriority,
error: function () { alert('ERROR'); showLoader(false); showEmptyTableMessage(true); }
}).then(function (data) {
drawTable(data);
showLoader(false);
});
};
func(URLTOSERVER);
FindServerUrlAsync(func);
}
function FindServerUrlAsync(callback) {
$.ajax({
type: "GET",
url: "/settings/ServerType"
}).then(function (serverType) {
var isDmz = (serverType === 'Dmz');
if (isDmz) {
$.ajax({
type: "GET",
url: "/settings/ServerUrl"
}).then(function (serverUrl) {
callback(serverUrl);
});
} else {
callback("");
}
});
}
The second server goes into a asp.net application controller (mvc) that uses an async request from an httpclient from the database.
web.config
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" />
</customHeaders>
</httpProtocol>
ASP.NET Startup
var corsBuilder = new CorsPolicyBuilder();
corsBuilder.AllowAnyHeader();
corsBuilder.AllowAnyMethod();
corsBuilder.AllowAnyOrigin();
corsBuilder.AllowCredentials();
services.AddCors(options =>
{
options.AddPolicy("AllowAll", corsBuilder.Build());
});
app.UseCors("AllowAll");
The request goes into the same asp.net application controller only in a different method / action (and obviously server). The web.config doesn't have a httprotocol (since I have been made aware that it's unnecessary).
I have been looking at this for a while now. But I can't seem to get it to work.
Edited
The problem was a combination of the following:
We eventually (after a few years) created a new MVC REST API Service. So I can't recall what application changes were made to make it work at the time.
This is our current Cors application code that makes it work.
In the App_Start -> WebApiConfig class for both the security service and the final (server) service application
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
EnableCorsAttribute enableCorsAttribute = new EnableCorsAttribute("*", "*", "*");
config.EnableCors(enableCorsAttribute);
config.MapHttpAttributeRoutes();
}
}