hello,
HttpContext after successful login, it is null in production but working currently in development Blazor Web App .Net 8 Interactive Auto.
I have added this authorizationhandler and assigned to httpClient in program.cs
public class AuthorizationHandler(IHttpContextAccessor httpContextAccessor) : DelegatingHandler
{
private readonly IHttpContextAccessor _httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor));
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var httpContext = _httpContextAccessor.HttpContext ??
throw new InvalidOperationException("No HttpContext available from the IHttpContextAccessor!");
if (httpContext != null && httpContext.Request.Cookies.TryGetValue("access_token", out var token))
{
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
}
return await base.SendAsync(request, cancellationToken);
} }
```program.cs
```ruby
services.AddTransient<AuthorizationHandler>();
var httpClientBuilder = services.AddHttpClient("ApiClient", client =>
{ client.BaseAddress = new Uri("https://localhost:7067/"); }).AddHttpMessageHandler<AuthorizationHandler>();
```why does this not working in production?