HttpContext lost between HttpClientWrapper and DelegatingHandler
See original GitHub issueExpected 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
- Create a
DelegatingHandler
that takes inIHttpContextAccessor
as an injected dependency. - Register the handler on the route.
- Add JWT auth to the route.
- In the
SendAsync
method, callhttpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value
- See that the value is null
Specifications
- Version: 15.0.7
- Platform: dotnet 3.1.300
- Subsystem: MacOS
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:15 (9 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@raman-m I use v18.0.0 where the issue is still present.
I no longer use this project so I won’t be going back to verify.