0

I have created the WEBAPI and trying to access the web api post method from Angular 4 application getting the following error.

Access to XMLHttpRequest at 'http://localhost:61611/api/Employees' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

And i am able to get the result from postman for api.

  • 2
    Possible duplicate of [Response to preflight request doesn't pass access control check](https://stackoverflow.com/questions/35588699/response-to-preflight-request-doesnt-pass-access-control-check) – selem mn Dec 27 '18 at 09:28
  • No, This is bit different i am getting this issue between angular 4 application and web api. – Jilla Sri Manidhar Dec 27 '18 at 09:34
  • There is no difference indeed, and that's not related to angular neither to web api. it is a common issue once trying to invoke webservices from a localhost source (which is not a trusted source by default) -> CORS – selem mn Dec 27 '18 at 09:39
  • Also related (re Postman): https://stackoverflow.com/q/36250615/1579626, https://stackoverflow.com/a/34931194/1579626, https://stackoverflow.com/a/36554935/1579626 – sǝɯɐſ Dec 27 '18 at 20:29

1 Answers1

0

We need to mention the following code in webapiconfig.cs

var cors = new EnableCorsAttribute("*", "*", "*");
config.EnableCors(cors);

After adding this code i am able to connect webapi from my angular application

Buddy
  • 10,120
  • 5
  • 37
  • 57