question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HttpContext lost between HttpClientWrapper and DelegatingHandler

See original GitHub issue

Expected Behavior / New Feature

A DelegatingHandler with IHttpContextAccessor injected can access the current context correctly.

Actual Behavior / Motivation for New Feature

As of version 15.0.7, a custom DelegatingHandler we use now only has access to an empty context and thus httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value is now null instead of the name like it was in 15.0.6

Steps to Reproduce the Problem

  1. Create a DelegatingHandler that takes in IHttpContextAccessor as an injected dependency.
  2. Register the handler on the route.
  3. Add JWT auth to the route.
  4. In the SendAsync method, call httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value
  5. See that the value is null

Specifications

  • Version: 15.0.7
  • Platform: dotnet 3.1.300
  • Subsystem: MacOS

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
AgentSharkcommented, Jun 28, 2023

@raman-m I use v18.0.0 where the issue is still present.

2reactions
amweisscommented, Jun 28, 2023

I no longer use this project so I won’t be going back to verify.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HttpContext.Current is null when adding delegate handler
For reference below is my DelegatingHandler implementation. Before this I defined two methods i.e. IncomingMessageAsync() , OutgoingMessageAsync ...
Read more >
HttpClient - DelegatingHandler - Correlation Id
Here we are checking the current request (using HttpContext via ICorrelationIdQuery), if it contains a valid correlation id, we will grab that ...
Read more >
Writing cleaner Typed HttpClient using a custom ...
Writing a typed HttpClient that forwards a JWT and logs errors · Read Access Token from HttpContext · Manage Access Token when it's...
Read more >
Use HttpContext in ASP.NET Core
HttpContext encapsulates all information about an individual HTTP request and response. An HttpContext instance is initialized when an HTTP ...
Read more >
DI scopes in IHttpClientFactory message handlers don't ...
In this post I discuss how handler DI scopes work in IHttpClientFactory, and how they're different to the request DI scope.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found