I have written API with .NET Core 3.0 Preview, and using Angular 8 for frontend. I have one method on User controller called DeleteUser. This is the method:
//DELETE users/d18da620-6e4d-4b1c-a1ec-36d89145f4ca
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteUser(Guid id) {
...
}
So, when request is performed with Angular like this:
this.usersApiService.deleteUser(userId).subscribe((data) => {
...
}
After this call is performed, I get following output in Visual Studio:
Microsoft.AspNetCore.Cors.Infrastructure.CorsService:Information: CORS policy execution successful.
Microsoft.AspNetCore.Routing.EndpointMiddleware:Information: Executing endpoint '405 HTTP Method Not Supported'
However, I've set custom CORS policy. In ConfigureServices I have this:
services.AddCors(options => {
options.AddPolicy("CorsPolicy",
builder => builder
.AllowAnyMethod()
.AllowCredentials()
.SetIsOriginAllowed((host) => true)
.AllowAnyHeader());
});
and in Configure method, I use this policy:
app.UseCors("CorsPolicy");
So my question is, how to successfuly call this delete method? What am I missing?
Edit: This is my deleteUser method that calls api
public deleteUser(userId) {
const httpOptions = {
headers: new HttpHeaders({
'Content-Type' : 'application/json'
}),
body: {
id: userId
}
};
return this.httpClient.delete(this.USERSENDPOINT, httpOptions);
}
usersApiService.deleteUsercode?