I deployed the application on the production server of my web.api and I get the following error in the browser console (seems solved):
Access to XMLHttpRequest at
'https://ebbtelemetrywebapi.azurewebsites.net/api//events' from origin 'https://ebbwatelem.azurewebsites.net' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Before this error I have the following (seems solved):
POST https://localhost:44340/api/events 500
The header of the called function is the following :
public async Task<IEnumerable<CosmosDBEvents>> GetAsync([FromBody]EventsGetTwoParamsDto dto)
The DTO declaration is the following :
public class EventsGetTwoParamsDto
{
public string DeviceIdorId { get; set; }
public string Action2 { get; set; }
}
and the ajax call is the following :
$.ajax({
type:"POST",
url: ENV.apiUrl+'/events',
data: JSON.stringify({DeviceIdorId: ENV.deviceId, Action2 : "Pagina5"}),
dataType: "json",
contentType: 'application/json;charset=UTF-8',
success: function(data){
console.log("RISPOSTA", data);
}
});
The Startup.cs/ConfigurationServices method contains the lines:
services.AddCors(); // Make sure you call this previous to AddMvc
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
and thr Startup.cs/Configure method contains :
app.UseCors(
options=> options.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials());
What am I doing wrong?
Thanks in advance. Simone
All the issues is related to the second one solved changing the declaration of the method in the controller as shown below :
[HttpPost]
public async
Task<IEnumerable<CosmosDBTelemetry>>GetAsync(TelemetriesTwoParamsDto dto)
Thanks to all, Simone