Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Cookie-based request credentials in Blazor

$
0
0

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 cookiesMy call to the api

Can anyone help me solve this problem?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>