c# - Issue: No 'Access-Control-Allow-Origin' header is present on the requested resource - TagMerge
1Issue: No 'Access-Control-Allow-Origin' header is present on the requested resourceIssue: No 'Access-Control-Allow-Origin' header is present on the requested resource

Issue: No 'Access-Control-Allow-Origin' header is present on the requested resource

Asked 1 years ago
1
1 answers

You should rearrange your middlewares as follows:

 app.UseHttpsRedirection();

 app.UseRouting();

 app.UseCors(builder =>
 builder.WithOrigins("http://localhost:4200")
 .AllowAnyHeader()
 .AllowCredentials()
 .AllowAnyMethod());

 app.UseDefaultFiles();
 app.UseStaticFiles();

 app.UseAuthentication();

 app.UseAuthorization();

 app.UseEndpoints(endpoints =>
 {
     endpoints.MapControllers();
 });

UseHttpsRedirection should be first of your middlewares, and UseCors should be before UseAuthentication/UseAuthorization, but after UseRouting.
Have a look at the docs

Source: link

Recent Questions on c#

    Programming Languages