1

I am buildind a Web Api app locally and I am calling the methods using simple jQuery ajax method calls. As per the title I have installed the Microsoft.AspNet.Cors package via nuget and enabled cors in my WebApiConfig.cs and on my controller like this

[EnableCors(origins: "https://localhost:44397", headers: "", methods: "", exposedHeaders: "X-My-Header")]

I have even tried this

[EnableCors(origins: "", headers: "", methods: "", exposedHeaders: "")]

but when I make the call via ajax I still get the error - Access to XMLHttpRequest at 'https://localhost:44397/api/Default/PostRegisterUser' from origin 'null' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Why is this happening and how do I resolve this?

ShatterStar
  • 99
  • 1
  • 1
  • 7
  • Does this answer your question? [How to enable CORS in ASP.net Core WebAPI](https://stackoverflow.com/questions/44379560/how-to-enable-cors-in-asp-net-core-webapi) – Fran Aug 31 '21 at 20:10
  • Hi I've gone through all the suggestions in the link above but still it doesn't work. – ShatterStar Sep 01 '21 at 06:04

0 Answers0