dotnet / dotnet/aspnetcore

[Analyzer] Detect IHttpContextAccessor usage

Open
#44,236 2 comments 1 reaction 0 assignees View on GitHub
analyzer area-networking
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

`IHttpContextAccessor` is problematic for a number of reasons, one of which is accessing non-threadsafe `HttpContext` on multiple threads.

https://learn.microsoft.com/en-us/aspnet/core/fundamentals/http-context?view=aspnetcore-6.0

### Describe the solution you'd like

An analyzer that provides information about potential problems with `IHttpContextAccessor`. Probably should be at Info level.

Options are either detecting this are either looking for `AddHttpContextAccessor` registration at startup. Or detect every time `IHttpContextAccessor.Current` is used.

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.