Search code examples
c#asp.netasp.net-mvccontrollercors

How to enable CORS in a C# application?


I'm building a C# application for which i have to update in database and that needs to make requests to an API running on a different domain. However, when I try to make these requests, I'm getting CORS errors.

I've read about CORS and understand that it's a security feature that browsers use to prevent cross-domain requests, but I'm not sure how to enable it in my C# application.

Can someone please explain how to enable CORS in a C# application and provide an example of how to make a cross-domain request using CORS? Thanks in advance!

I had tried to install "Microsoft.AspNetCore.Cors" from package manager but is not working.


Solution

  • using (var client = new HttpClient())