Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

241
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!