I have a C# .NET (v4.8) WCF service that is being accessed by an Angular 14 site. I have set them up as separate websites on my local machine (Angular site is localhost, WCF service is localhost:4506).
I'm getting a CORS error when the Angular site tries to access the services on the WCF site. Google foo says that to correct the problem, I have to add the following to the Gobal.aspx.cs file for my service:
protected void Application_BeginRequest(object sender, EventArgs e) {
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
if(HttpContext.Current.Request.HttpMethod == "OPTIONS") {
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "*");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "*");
HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
HttpContext.Current.Response.End();
}
}
I've added that, published the new code, and I'm still getting the CORS error.
I've also tried adding this to the web.config:
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*"/>
<add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept"/>
</customHeaders>
</httpProtocol>
No success with this or a couple of other variations of this.
What else can I try?