In this video, learn how to add the CORS middleware to an ASP.NET Core API, and how to configure it properly depending on the policy you need.
- [Instructor] If you've decided that your API does need cors, adding it to the asp.net core pipeline is simple. In startup.cs, go down to the configure services method and we'll add services.AddCors. And we'll specify some options. We'll do options.AddPolicy to create a cors policy. Then we'll specify a string name, we'll just call this AllowMyApp. This can be any name you want. Then to build the policy, we'll say policy.WithOrigins and we'll specify the applications origin here.
This is the browser origin that'll be making requests. During development, sometime it can be useful to change this out for .AllowAnyOrigin just while you're doing testing. When you move to production, you should remove any of these any wildcard settings and lock down cors to just the origins that you need to use. Don't forget down in the configure method we also need to add it here. We need to say app.UseCors. And specify the name of that policy which we said was AllowMyApp.
It's important that UseCors is above any middle wear that generates a response such as UseNVC. If you need more help with cors there's plenty of documentation available on the asp.net cor documentation site at docs.asp.net.
- What is RESTful design?
- Building a new API with ASP.NET Core
- Using HTTP methods
- Returning JSON
- Creating RESTful routing with templates
- Securing RESTful APIs with HTTPS
- Representing resources
- Representing links
- Representing collections
- Sorting and searching collections
- Building forms
- Adding caching to an ASP.NET Core API
- Configuring user authentication and authorization
Skill Level Intermediate
1. REST API Concepts
2. Build a Basic API
3. Versioning and Errors
4. Secure the API
5. Represent Resources
6. Represent Links
7. Represent Collections
Add pagination7m 37s
8. Sorting Collections
9. Searching Collections
10. Forms and Modifying Data
11. Caching and Compression
12. Authentication and Authorization
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.