I am trying to send a request from an angular application and an ASP.NET web API both running in localhost on two different ports. When sending a request from the angular app(frontend) to the Web API I am getting a CORS error that "No 'Access-Control-Allow-Origin' header is present on the requested resource".
I tried a lot of ways to try to solve this issue like enabling cors in the WebApiConfig class, custom headers in the web.config and intercepting pre-flight checks but still, the issue occurred.
WebApiConfig.cs
var corsAttr = new EnableCorsAttribute("*", "*", "*");
config.EnableCors(corsAttr);
Web.config
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type,
Access-Control-Allow-Headers, Authorization, X-Requested-
With, X- AuthToken" />
<add name="Access-Control-Allow-Methods" value="GET, POST, PUT,
DELETE, OPTIONS" />
</customHeaders>
</httpProtocol>
<modules runAllManagedModulesForAllRequests="true">
<add name="HandleOptions" type="OptionsModule" />
</modules>
</system.webServer>