-2

Kept Withcredetials = true to get cookies in Angular HttpClient post request but getting CORS error (backend is .net core)

"from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute"

1 Answers1

0

While passing Withcredetials = true from UI, you need to add 2 items in the backend while handling CORS.

Firstly, in Origins, you have to add client url (wildcard (*) is not allowed)

Secondly, add SupportsCredentials = true

Example:

[EnableCors(origins: "http://exampleclient.com", headers: "*", 
methods: "*", SupportsCredentials = true)]
Adrita Sharma
  • 21,581
  • 10
  • 69
  • 79