Cors issue specifically in Internet Explorer only when calling API from ajax call.
1)Request header content-type was not present in the Access-Control-Allow- Headers list 2)XMLHttpRequest: Network Error 0x80070005, Access is denied.
I tried by followings
xhrFields: {
withCredentials: true
}
also by setting ...
Ajax call
var url = "https://dev-connectivity.dummylink";
var data = JSON.stringify({
"lang": "en",
"ClientId": "asdfasf3452345c42352345c",
"CountryCode": "34"
});
$.ajax({
url: url,
type: 'POST',
contentType: 'application/json; charset=utf-8',
headers: {
'Access-Control-Allow-Origin': '*' },
data: data,
success: function (data) {
alert("tets");
},
error: function (error) {
alert("error");
}
});
//My api Webconfig code
<httpProtocol>
<customHeaders>
<remove name="Access-Control-Allow-Origin" />
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="*" />
<add name="Access-Control-Allow-Headers" value="*" />
</customHeaders>
</httpProtocol>
// also Enabling Cors in startup
services.AddCors(o => o.AddPolicy("CorsPolicy", builder =>
{
builder.AllowAnyMethod()
.AllowAnyHeader();
}));
app.UseCors("CorsPolicy");
IE doesn't accept Content-Type header if you have provided * in you web.config file so to fix this issue, you need to manually add Content-Type header in Access-Control-Allow-Headers list inside your web.config file.
<customHeaders>
<remove name="Access-Control-Allow-Origin" />
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type, Any-Other-Header" />
</customHeaders>
User contributions licensed under CC BY-SA 3.0