I have a Web API I wrote and one application utilizing it. SO I added CORS header for that applicaiton by adding a header to the controller class within my API:
[EnableCors(origins: "http://localhost:59452", headers: "*", methods: "*")]
The above worked fine. Now I also want more applications consuming that web API. My question is how do I make this happen?
Say the front-end is served from https://demodomain-ui.com and the backend is served from from https://demodomain-service.com/api. If an end user tries to access the application, for security reasons the browsers restrict cross-origin HTTP requests initiated from the UI. The first is to install the Microsoft. AspNet.
CORS is typically required to build web applications that access APIs hosted on a different domain or origin. You can enable CORS to allow requests to your API from a web application hosted on a different domain.
Cross-origin resource sharing (CORS) is a browser security feature that restricts cross-origin HTTP requests that are initiated from scripts running in the browser. If your REST API's resources receive non-simple cross-origin HTTP requests, you need to enable CORS support.
You can add multiple origins by separating them with commas:
[EnableCors(origins: "http://localhost:59452,http://localhost:25495,http://localhost:8080", headers: "*", methods: "*")]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With