From the course: Advanced ASP.NET Web API 2.2

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Setting CORS origins and HTTP methods

Setting CORS origins and HTTP methods

From the course: Advanced ASP.NET Web API 2.2

Start my 1-month free trial

Setting CORS origins and HTTP methods

- So far, we have configure CORS, but we have put a star on each of the options, which means we allow our API endpoint to be used by any app, any header, and any method, which is bad, because it means that even apps that we did not authorize can access our API endpoint. So, let us go and see how we can customize our course endpoint. In our solution explore, go to the web API.dependency injection project and then inside the controllers folder, you'll have the students controller. Here in the enable course method when you find all these properties, star (*), which means everything. Now, the first property in here, stands for the origins, who can even write in here, origins, and then define the values. So, when you write a star it means that our API endpoint can be accessed or can be requested from any application, and this is not the case because we always need to define which apps or which endpoints have access to our API. So let…

Contents