-2

Access to fetch at 'http://URL' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

I got the above error in console .But I have enabled the CORS in WEB API other API requests are not showing this error.

service :

 ViewPDF(mMagazineId){
    return this.http.get(this.BASE_URL + `/api/ViewPDF/?mMagazineId=${mMagazineId}`);
  }

WebApiConfig.cs

 config.EnableCors(new EnableCorsAttribute("*", headers: "*", methods: "*"));

I am really confused with this issue .Can anyone help me to solve this.

Zhu
  • 3,679
  • 14
  • 45
  • 76
  • I had a similar issue and what solved it was by changing the configuration at the Web Server (Tomcat in my case). – FDavidov Dec 30 '18 at 14:29
  • You're configuring it improperly. Just read Microsoft's help pages and other resources like this: [click](https://stackoverflow.com/questions/18619656/enable-cors-in-web-api-2). – Alexander Leonov Dec 30 '18 at 16:36

2 Answers2

0

You should change server properties for allow to CORS if you can. How to do it.

If you dont have access to change server properties you could try call api with JSONP. Its not easy as JSON call. I have tried it but server didnt let me to do that too.

Cem Kocagöz
  • 634
  • 12
  • 26
0

Check the backend entity property and json model passed from angular they are equal even the case it matters.

Addisalem
  • 108
  • 4