-1

Can you help me out? I am currently stuck on solving this problem. I created a .Net Core Rest API that is hosted in Azure. I am using that rest API using my reactjs application. Whenever I try to access it's giving me this error.

enter image description here

And here is my rest API startup.cs

enter image description here

Below is my ReactApplication enter image description here

Am I doing something wrong?

Note: the URL where my reactjs application is located is "https://clienturl.com"

Oussama Bouthouri
  • 615
  • 2
  • 8
  • 23
Hawk
  • 514
  • 1
  • 7
  • 22
  • Have you added the CORS middleware in the Configure method in Startup also? – juunas Oct 08 '20 at 06:40
  • Before hosting the web application to Azure, whether the request success or not? I found a thread, it seems that in Azure portal there is a CORS section, try to check it in Azure, make sure it allowed the related origins. Reference: [ASP.NET Core CORS WebAPI: no Access-Control-Allow-Origin header](https://stackoverflow.com/questions/40908949/asp-net-core-cors-webapi-no-access-control-allow-origin-header) – Zhi Lv Oct 08 '20 at 09:21

1 Answers1

0

This error is due to CORS, which means that a resource in a domain name A can't access another resource in domain name B without prior permission.
You can give enable CORS for your frontend app in the backend server, or if it's just for development use this plugin

Oussama Bouthouri
  • 615
  • 2
  • 8
  • 23
  • 1
    am... Sorry but I don't think installing a plugin is a good option. Was wondering if I can find a solution that I just need to fix something in my code – Hawk Oct 08 '20 at 06:27
  • 1
    your code is fine you just need to enable CORS in the API server as I suggested, please take a look at the link I shared. – Oussama Bouthouri Oct 08 '20 at 06:30