0

I am using owin to generate oAuth token in asp.net webapi and I have added the UserCors as the 1st line in Configuration in Statrup.cs

public void Configuration(IAppBuilder app)
{
    app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
    ConfigureOAuth(app);
}

I also added it again inside ConfigureOAuth(app);

I manually tried to add header inside GrantResourceOwnerCredentials like below

context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });

But didn't works. I keep getting the error No 'Access-Control-Allow-Origin' header is present on the requested resource from angular side.

When I add the headers in the config file it says duplicate.

<customHeaders>
<add name="Access-Control-Allow-Origin" value="http://localhost:4200" />
<add name="Access-Control-Allow-Methods" value="GET, POST, OPTIONS, PUT,DELETE" />
</customHeaders>

Not sure what's going on.

bomaboom
  • 190
  • 1
  • 14
  • Check what **header** you send. My header was content-type and had to add it to the **customheaders**. The header origin and methods has to match in the request and responce headers. – Swoox Dec 15 '17 at 14:11
  • Can you please give me more details about the custom header? I am using 'Content-Type': 'application/x-www-form-urlencoded' – bomaboom Dec 19 '17 at 05:54

1 Answers1

0

The trick is to delete the Global.asax and call the WebApiConfig.Register from the startup file. This link helped me.

bomaboom
  • 190
  • 1
  • 14