0
votes

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.

1
No, This is bit different i am getting this issue between angular 4 application and web api. - Jilla Sri Manidhar
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

1 Answers

0
votes

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