Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

236
Vistas
How to save a cookie or get any headers from asp.net web api to client with CORS?

I can't save a cookie or get any headers from asp.net web api using CORS. But in postman I can see every header or cookie set in response.

My frontend request:

var response = await fetch("https://localhost:7072/api/Auth/Register", {
            method: "post",
            mode: "cors",
            credentials: "same-origin",
            headers: {
                "Origin": "https://localhost:3000"
            },
            body: new FormData(document.getElementById("myForm"))
        });
        response.headers.forEach((val, key) => console.log(key + ": " + val));

I also tried credentials: include but I cant get the headers anyway

But in response headers I get only content-length: 0 and no cookie set.

My backend policy is:

builder.Services.AddCors(options => 
{
    options.AddPolicy("CorsPolicy", builder =>
    {
        builder.WithOrigins("https://localhost:3000")
        .AllowAnyHeader().
        AllowCredentials().
        AllowAnyMethod();
    });
});

Build:

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseCors("CorsPolicy");

app.UseAuthentication();
app.UseAuthorization();

app.MapControllerRoute(
    name: "default",
    pattern: "{controller}/{action=Index}/{id?}");

app.MapFallbackToFile("index.html"); ;

app.Run();

And Auth/Register looks like:

var token = GenerateToken(user);
Response.Cookies.Append("LOGIN_INFO", token, new CookieOptions
{
    Expires = DateTime.Now.AddMonths(3),
    HttpOnly = true,
    Secure = true
});
return Ok();

I tried using SameSite.None, Lax etc.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda