I am working on an application using angular 4 and Web api. I am getting CORS error even I have kept code in Web.config , Start Up, WebApiConfig and on Controller as well but still i am getting this error. I don't to how to figure it out. Here is my code examples
Startup.cs
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
WebApiConfig
var cors = new EnableCorsAttribute("*", "*", "*");
config.EnableCors(cors);
Web.Config
<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" />
</customHeaders>
</httpProtocol>
Controller
[EnableCors(origins: "*", headers: "*", methods: "*")]
[ApiVersion1RoutePrefix("Settings")]
public class SettingsController : ApiController
Even someone asked to remove this tag as well from web config and i also did this
<!--<remove name="OPTIONSVerbHandler" />-->
My angular call is here
public getbyString<T>(apiUrl:any,param: string): Observable<T> {
let _options = { headers: new HttpHeaders(
{
'Content-Type': 'application/json',
'Authorization': 'Bearer '+ localStorage.getItem('access_token')
}
)};
return this.http.get<T>(this.actionUrl+apiUrl +"?version="+param,_options);
}
Please see the below to see the error.
I have done this all but no success yet.