Im running ASP.NET Core Angular app, I added a Api Controller in the Core app and Im trying to make a api call from the Angular app, the Core app is hosted on 58181 and the Angular app on 44337, when I try to call the Api from the Angular a get
Access to XMLHttpRequest at 'http://localhost:58181/api/authenticate/login' from origin 'https://localhost:44337' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.
I configue Cors in the API
services.AddCors(options =>
{
options.AddPolicy("CorsPolicy", policy =>
{
policy.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod();
});
});
app.UseCors("CorsPolicy");
Im trying to call the API like this
register() {
var body = {
UserName: this.formModel.value.UserName,
Email: this.formModel.value.Email,
FullName: this.formModel.value.FullName,
Password: this.formModel.value.Passwords.Password
};
return this.http.post(this.BaseURI + '/authenticate/register', body, {
headers: new HttpHeaders({
'Access-Control-Allow-Origin':'*',
'Content-Type': 'application/json',
'Authorization':'authkey',
'userid':'1'
})});
}
What I expect is to call my authentication controller and login/register my user, both Angular app and Apis will be on the same localhost, on different ports.