(ASPNET Core Exercises) Practice Exercises on CORS in ASPNET Core

This is a collection of exercises on CORS in ASPNET Core. Solutions have been provided for almost all of them.
(Rev. 31-Oct-2024)

Categories | About |     |  

Parveen,

Table of Contents (top down ↓)

Exercise 1 - Create an ASPNET Core WebApi Project that listens to GET request on a route /check, and responds with a string called "hello api!". Create an HTML Page called index.html OUTSIDE your project - on, let's say, the Desktop. The HTML Page contains a hyperlink to make a call to the /check API. Do you expect the call to succeed? Next add a button to the same HTML Page that makes a javascript based AJAX GET request to the same API. Will it succeed?

Solution ⟹ Please refer this →

The above link leads to our course on ASPNET Core Solution + Projects + Exercises + Tutorials + Interview Questions please visit the link.

Exercise 2 - Write a C# Console application that sends a GET request to a URL and prints the response headers. You can make an internet search for "MSDN Make HTTP requests with the HttpClient class" for help on the few lines of code that you will need. First make a GET request to "https://google.com", and then make another request to a CDN such as "https://cdn.jsdelivr.net/npm/bootstrap". Examine the response headers to determine which one permits a COR?

Solution ⟹ Please refer this →

The above link leads to our course on ASPNET Core Solution + Projects + Exercises + Tutorials + Interview Questions please visit the link.

Exercise 3: The default settings of an ASPNET Core website prevent cross-site requests to its home page. Verify with curl that this indeed is the case. How will you enable cross-site access to the pages of your website?

Solution ⟹ Please refer this →

The above link leads to our course on ASPNET Core Solution + Projects + Exercises + Tutorials + Interview Questions please visit the link.

Exercise 4: There is an ASPNET Core website that contains two pages - Index and Payments. How will you configure it so that cross-origin requests to "Index" are allowed ONLY from "microsoft.com", whereas cross-origin requests to "Payments" are allowed ONLY from "google.com"?

Solution ⟹ Please refer this →

The above link leads to our course on ASPNET Core Solution + Projects + Exercises + Tutorials + Interview Questions please visit the link.

Exercise 5: [CORS and Static Files] An ASPNET Core Website has two static pages called "page1.html" and "page2.html". How will you configure your website so as to allow cross-origin requests to "page1.html" but not to "page2.html"? Verify with "curl".

Solution ⟹ Please refer this →

The above link leads to our course on ASPNET Core Solution + Projects + Exercises + Tutorials + Interview Questions please visit the link.


This Blog Post/Article "(ASPNET Core Exercises) Practice Exercises on CORS in ASPNET Core" by Parveen is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.