.NET Core

How To Solve The CORS Or The Access-Control-Allow-Origin Header Error In .NET

In this article, we will see how we can quickly solve Access-Control-Allow-Origin Heade error or cors origin error in .NET.

I’m quite sure all developers, facing this issue once in their developer life, lol!. normally when we are working with APIs this issue can come if a request is from another origin and at that time our reaction is:

source: NBA Memes

To solve this issue we just need to enable CORS in an application. Here I’ll share one best way to solve Access-Control-Allow-Origin Header error.

Open web.config file and find “<system.webServer>” tag. Copy following code and paste inside that tag.

      <httpProtocol>
  <customHeaders>
    <add name="Access-Control-Allow-Origin" value="*" />
    <add name="Access-Control-Allow-Headers" value="Content-Type" />
    <add name="Access-Control-Allow-Methods" value="GET,POST,PUT,DELETE,OPTIONS" />
    <add name="Access-Control-Allow-Credentials" value="true" />
  </customHeaders>
</httpProtocol>

Your web.config will look like this.

And done, after applying this thing Access-Control-Allow-Origin Header error will be gone.

hope you guys found something useful. Please give your valuable feedback/comments/questions about this article. Please let me know how you like and understand this article and how I could improve it.

Faisal Pathan

Faisal Pathan is a founder of TheCodeHubs, .NET Project Manager/Team Leader, and C# Corner MVP. He has extensive experience with designing and developing enterprise-scale applications. He has good skills in ASP.NET C#, ASP.NET Core, ASP.NET MVC, AngularJS, Angular, React, NodeJS, Amazon S3, Web API, EPPlus, Amazon MWS, eBay Integration, SQL, Entity Framework, JavaScript, eCommerce Integration like Walmart, Tanga, Newegg, Group-on Store, etc. and Windows services.

Recent Posts

Testing hk

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Operation

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

TETS NEW

test

2 years ago