I have a C# WebApi server and in this project, I have enabled cors in my WebAPiConfig.cs
var cors = new EnableCorsAttribute(
origins: "*",
headers: "*",
methods: "*" );
cors.SupportsCredentials = true;
config.EnableCors(cors);
In my angular service, I set the HTTP headers like this
getRouteGeneralTable(routeType: string, pattern: string): Observable<DBrow[]> {
const httpHeader = new HttpHeaders({
'Content-Type': 'application/json',
'withCredentials': 'true',
'Access-Control-Allow-Origin':'*',
'Accept': 'application/json',
'Access-Control-Allow-Credentials': 'true',
'Access-Control-Allow-Methods': 'POST, GET, OPTIONS, PUT'
});
return this.http.get<DBrow[]>(this.baseURL + 'getgeneralroutedata/' + routeType + '/' + pattern, {headers: httpHeader} )
.pipe(
retry(3),
catchError(this.handleError)
);
}
I'm getting these errors when trying to do a get request:
Access to XMLHttpRequest at SOMEADDRESS from origin 'http://localhost:4200' has
been blocked by CORS policy: Response to preflight request doesn't pass
access control check: No 'Access-Control-Allow-Origin' header is present on
the requested resource.
How can I fix it, please?