sábado, 4 de julio de 2020

DataTables, TypeError: Cannot read property 'style' of undefined

I had this problem on my dataTables library, searching I found that my fields on the array had more fields that html columns.😓

miércoles, 1 de julio de 2020

Cors error fetch on React

Hello guys, I'm going to show you how I fix this common error to call a .Net API.

There are many scenarios that can affect your project and cause this error. In my case, My project was using annotation in any endpoint and in the .webconfig there are the next XML

      <httpProtocol>
        <customHeaders>
          <add name="Access-Control-Allow-Origin" value="*" />
          <add name="Access-Control-Allow-Headers" value="Content-Type" />
          <add name="Access-Control-Allow-Methods" value="GET,POST,PUT,DELETE,OPTIONS" />
         <add name="Access-Control-Allow-Credentials" value="true" />
        </customHeaders>
      </httpProtocol>

I delete it and then remove the anotation of my Post endpoint. 


 [Route("signaltracer/Reports/GetSignalByCutomerId")]
 [HttpPost]
 public List<ChartJsonData> LockLimits(string pidCustomer = "")

Next,

1- Install the nugget package Microsoft.AspNet.WebApi.Cors


2- add an annotation to a class 
 [EnableCors("*", "*", "*")]
  public class ReportsController : ApiController
  {

3- in the folder App_Start/WebApiConfig.cs, add the next code

  var cors = new EnableCorsAttribute("*", "*", "*");
  config.EnableCors(cors);
  config.MapHttpAttributeRoutes();

and I make a little modification to my endpoint function 


public ChartLimits LockLimits([FromBody]ChartLimits limitsParams)
 {