I have two applications:
- ASP.NET Core MVC web app
- ASP.NET Core Web API
When I run the applications on my computer, everything works and the MVC app can make get/post http requests to my API.
When I publish to the server, my LOCAL MVC app still can make the get/post http requests.
But when the ASP.NET Core MVC app is published to the server, it can make just Get requests, but not Post requests anymore.
Both application are on the same server, under the same domain. Both use http and not https.
Does someone know if I'm missing something?
I tried a lot of things: learnt about CORS origin, transfer to http or https. Change the url to post...
This is a problem of CORS where the browser does prevent the call of your rest apis when anybody tries it from postman or other URLs. Basically what you can do is create CORS policy and allow them as per your requirement.
Here is how you can do this in your program.cs or startup.cs file
You can find more information about this at following links
https://www.bytehide.com/blog/cors-aspnet-core
https://learn.microsoft.com/en-us/aspnet/core/security/cors?view=aspnetcore-8.0
https://medium.com/@M-B-A-R-K/what-is-cors-in-asp-net-core-85f4903c9d43