I'm using blazor .net with interactive auto and individual accounts. When I send a request from the client to my server/api, I can't insert the cookies in the request header.
Following the documentation I tried this approach.
My client:
public class CookieHandler : DelegatingHandler{ protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { request.SetBrowserRequestCredentials(BrowserRequestCredentials.Include); request.Headers.Add("X-Requested-With", ["XMLHttpRequest"]); return base.SendAsync(request, cancellationToken); }}builder.Services.AddTransient<CookieHandler>() .AddScoped(sp => sp .GetRequiredService<IHttpClientFactory>() .CreateClient("API")) .AddHttpClient("API", client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress)).AddHttpMessageHandler<CookieHandler>();My server:
builder.Services.AddScoped(http => new HttpClient{ BaseAddress = new Uri("https://localhost:7138")});In the following image, my httpClient doesn't have cookies
Can anyone help me solve this problem?