Cross-origin resource sharing (CORS) & Web API

Arharbi, Adnane 136 Reputation points
2021-07-24T15:12:55.567+00:00

Hi,

Why CORS Is needed in WEB API?

Any clair and good documentation ?

Thank you !

Developer technologies ASP.NET ASP.NET Core
0 comments No comments
{count} vote

Accepted answer
  1. Erik Van Slyke 81 Reputation points
    2021-07-24T15:48:33.323+00:00

    For the API side of things CORS is just a header you add to the response so that any browser that implements CORS will check for. If no CORS is enabled on your API, then a browser will not accept any responses from your API. Either you can add the domain name of the web application to the Access-Control-Allow-Origin header value, or a wild card i.e. "*" if you want the API to be used by any web application.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Om Mishra 1 Reputation point
    2021-07-27T01:30:23.727+00:00

    Cross Origin Resource Sharing (CORS) is a W3C standard that allows a server to relax the same-origin policy. Using CORS, a server can explicitly allow some cross-origin requests while rejecting others.

    This might be helpful https://learn.microsoft.com/en-us/aspnet/web-api/overview/security/enabling-cross-origin-requests-in-web-api

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.