Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

296
Visualizações
Net Core Webapi/SignalR app blocked by CORS policy (netcore 5 with net framework 4.7.2. FE consumer)

I have a net framework 4.7.2 FE which I would like to consume a new netcore 5 webapi/signalR application.

At the moment I have both running on my machine with the FE in VS2017 under local IIS (https://local.redacted.com) and latter in VS2019 IIS Express and both are span up with the play/debug button.

I have installed cors nuget for netcore and have the following in my startup:

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddCors(c =>
            {
                c.AddPolicy(
                    "AllowCCORSOrigin",
                    options => options.WithOrigins("https://local.redacted.com/")
                        .AllowAnyMethod()
                        .AllowAnyHeader()
                        .AllowCredentials());
            });
        services.AddControllers();
        services.AddSingleton<KillChecker>();
        services.AddHttpContextAccessor();
        services.AddSignalR().AddMessagePackProtocol();
        services.AddSignalR(
            o =>
                {
                    o.EnableDetailedErrors = true;
                });
    }

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

        app.UseFileServer(); //needed?
        app.UseStaticFiles();
        app.UseRouting();

        app.UseCors(builder =>
            {
                builder
                    .WithOrigins("https://local.redacted.com/")
                    .AllowAnyMethod()
                    .AllowAnyHeader()
                    .AllowCredentials();
            });
        
        app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapHub<KillHub>("/killhub");
            });
    }
}

I also decorated my Launch controller with:

[Route("[controller]"), EnableCors()]
public class LaunchController : Controller

From the FE application I am getting the following CORS error when running my JS:

const options = {
    method: "POST",
    body: JSON.stringify(params),
    headers: {
        'content-type': "application/json"
    }
};
fetch("https://localhost:60907/Launch", options)
    .then(response => response.json())
    .then(data => console.log(data))
    .then(console.log('lift off'));

Access to fetch at 'https://localhost:60907/Launch' from origin 'https://local.redacted.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda