1

I have problem when I call api for put and delete from swagger, error is: TypeError: Failed to fetch

Curl

curl -X DELETE "http://localhost:5000/api/Ad/2" -H "accept: application/json" -H "Authorization: Bearer MY_TOKEN"

From setup I had enable cors like this and put on begin of ConfigureService method:

services.AddCors(options => {
    options.AddPolicy(
        "AllowAll",
        builder => builder.AllowAnyOrigin()
                          .AllowAnyMethod()
                          .AllowAnyHeader()
                          .AllowCredentials()
    );
});

thus from Configure before anything is put it app.UseCors("AllowAll");

Why I'm not able to call delete method and put?

Update 1 enter image description here enter image description here

Reagrds, Danijel

Danijel Boksan
  • 779
  • 1
  • 13
  • 30

1 Answers1

-1

Instead of app.UseCors("AllowAll") can you try [EnableCors("AllowAll")] on the controller endpoints? Also refer: How to enable CORS in ASP.NET Core

Socratees Samipillai
  • 2,985
  • 1
  • 20
  • 20
  • I had removed app.UseCors("AllowAll") and put [Route("api/[controller]")] [Authorize(Roles = "Admin,Member")] [EnableCors("AllowAll")] public class AdController : ControllerBase Problem still present – Danijel Boksan Jun 12 '19 at 19:22