skip to Main Content

I am using ASP.NET framework with Angular 18. I am trying to delete a row but whenever I try to delete, I get this error:

Response to preflight request doesn’t pass access control check: It does not have HTTP ok status

I had tried all the ways to enable Cors or to use proxy.config.json file – but nothing worked.

Fyi the project gets the data normally but the problem appears in delete

enter image description here

enter image description here

I have tried all possible ways in the backend; I tried to enable Cors in my web.config and global.asax

In Angular I tried proxy file

2

Answers


  1. In CORS mechanism , the browser makes an "Option" called request "preflight" to your method ,if the response will "200- OK" the the browser continues with the main request if it fails , then the CORS error will be raised.

    So in your case there might be an exception in your action that makes the preflight request fail. you can also use postman to make your request and trace it from the beginning of request pipeline to spot the problem .

    Login or Signup to reply.
  2. try

    [Route("api/EvaluationSetup/deleteEvaluation/{evalCode}]
    [HttpDelete]
    public HttpResponseMessage deleteEvaluation(int evalCode) { ... }
    

    And call it from angular as

    this.httpClient.delete('api/EvaluationSetup/deleteEvaluation/10')
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search