This is the error occurs in the Client application
that is consuming the WEB API. There might be two different reasons,
Web API by
default doesn’t allow Service to be consumed from different domains.
1. RESOLVED BY CORS:
[WEB API APPLICATION]
Open Tools -> NuGet Package
Manager - > Package Manager Console
And install NuGet
packages
Install-Package
Microsoft.AspNet.WebApi.Cors
GO to WebApiConfig.cs
Add [
using
System.Web.Http.Cors; ]
namespace in webapiConfig.cs file
EnableCorsAttribute cors = new
EnableCorsAttribute("*", "*", "*");
CONFIG.EnableCors(cors);
First star resembles allow requests from all domains,
else we can specify specific client URLS, separated by comma (,).
Second
star resembles allow requests for all the headers.
Third
star resembles allow requests for all the methods like POST, GET, PUT, DELETE,
etc
2. RESOLVED BY REMOVING HEADERS IN
CLIENT REQUEST[AFTER CORS IMPLEMENTATION]