• This topic has 1 reply, 2 voices, and was last updated 1 month ago by john.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts

  • kevin
    Keymaster
    Postcount 41

    Hi all,

    I’m developing a app use Angular 8. I want call web api from ASP.NET Core but I’m getting errors with CORS. How can I config to resolve it?


    john
    Participant
    Postcount 3

    You can use sample code below:

    using BasicAuthenticationWithASPNETCoreAPI.Middlewares;
    using Microsoft.AspNetCore.Builder;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.Extensions.Hosting;

    namespace BasicAuthenticationWithASPNETCoreAPI
    {
    public class Startup
    {

    public void ConfigureServices(IServiceCollection services)
    {
    services.AddCors();

    services.AddControllers();
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
    if (env.IsDevelopment())
    {
    app.UseDeveloperExceptionPage();
    }

    app.UseCors(builder => builder
    .AllowAnyHeader()
    .AllowAnyMethod()
    .SetIsOriginAllowed((host) => true)
    .AllowCredentials()
    );
    app.UseMiddleware<CorsMiddleware>();
    app.UseRouting();

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

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Top