MyCSharp.HttpUserAgentParser.AspNetCore
4.0.1
Requires NuGet 2.12 or higher.
dotnet add package MyCSharp.HttpUserAgentParser.AspNetCore --version 4.0.1
NuGet\Install-Package MyCSharp.HttpUserAgentParser.AspNetCore -Version 4.0.1
<PackageReference Include="MyCSharp.HttpUserAgentParser.AspNetCore" Version="4.0.1" />
<PackageVersion Include="MyCSharp.HttpUserAgentParser.AspNetCore" Version="4.0.1" />
<PackageReference Include="MyCSharp.HttpUserAgentParser.AspNetCore" />
paket add MyCSharp.HttpUserAgentParser.AspNetCore --version 4.0.1
#r "nuget: MyCSharp.HttpUserAgentParser.AspNetCore, 4.0.1"
#:package MyCSharp.HttpUserAgentParser.AspNetCore@4.0.1
#addin nuget:?package=MyCSharp.HttpUserAgentParser.AspNetCore&version=4.0.1
#tool nuget:?package=MyCSharp.HttpUserAgentParser.AspNetCore&version=4.0.1
MyCSharp.HttpUserAgentParser.AspNetCore
ASP.NET Core integration for MyCSharp.HttpUserAgentParser.
Repository: https://github.com/mycsharp/HttpUserAgentParser
Install
dotnet add package MyCSharp.HttpUserAgentParser.AspNetCore
Quick start
Register a provider (any of the available ones) and then add the accessor:
The accessor reads the User-Agent header of a request, parses it using the registered provider, and caches the result per request in HttpContext.Items (so repeated calls within the same request neither re-parse nor emit duplicate telemetry events). There are two options:
AddHttpUserAgentParserAccessor()registersIHttpUserAgentParserAccessor: you pass theHttpContext(Get(httpContext)). Recommended.AddHttpUserAgentParserContextAccessor()registersIHttpUserAgentParserContextAccessorandIHttpContextAccessor:Get()uses the current request,Get(httpContext)works as well. Useful in services without access to theHttpContext;IHttpContextAccessorhas a small cost on every request.
services
.AddHttpUserAgentMemoryCachedParser() // or: AddHttpUserAgentParser / AddHttpUserAgentCachedParser
.AddHttpUserAgentParserAccessor(); // or: .AddHttpUserAgentParserContextAccessor()
Usage with the HttpContext:
public sealed class MyController(IHttpUserAgentParserAccessor accessor) : ControllerBase
{
[HttpGet]
public HttpUserAgentInformation? Get() => accessor.Get(HttpContext); // null without (or with an empty) User-Agent header
}
// Minimal API
app.MapGet("/ua", (HttpContext context, IHttpUserAgentParserAccessor accessor) => accessor.Get(context));
Usage with the current request (AddHttpUserAgentParserContextAccessor()):
public sealed class MyService(IHttpUserAgentParserContextAccessor accessor)
{
public bool IsRobot() => accessor.Get()?.IsRobot() ?? false; // null outside of a request or without User-Agent header
}
The package is trimming and Native AOT compatible.
Just read the header
If you only want the raw User-Agent string:
string? ua = HttpContext.GetUserAgentString();
Telemetry (EventCounters)
Telemetry is modular and opt-in.
Enable (Fluent API)
services
.AddHttpUserAgentParser()
.AddHttpUserAgentParserAccessor()
.WithAspNetCoreTelemetry();
The accessor registration returns the same options object, so you can chain this after any parser registration.
EventSource + counters
EventSource: MyCSharp.HttpUserAgentParser.AspNetCore (constant: HttpUserAgentParserAspNetCoreEventSource.EventSourceName)
useragent-present(incrementing)useragent-missing(incrementing)
Monitor with dotnet-counters
dotnet-counters monitor --process-id <pid> MyCSharp.HttpUserAgentParser.AspNetCore
Telemetry (native Meters)
This package can also emit native System.Diagnostics.Metrics instruments.
Enable meters (Fluent API)
services
.AddHttpUserAgentParser()
.AddHttpUserAgentParserAccessor()
.WithAspNetCoreMeterTelemetry();
Pass your own Meter to WithAspNetCoreMeterTelemetry(meter) to record to it. A later registration with another meter
replaces the previous one, which then neither records nor reports values; a meter that is registered again reuses its instruments.
The meter the package creates itself (without argument or with a prefix) is reused for the same name and disposed when another
meter replaces it; a measurement that runs exactly during that switch may be lost. Meters you pass in are never disposed.
Meter + instruments
Meter: mycsharp.http_user_agent_parser.aspnetcore (the prefix mycsharp. can be changed with WithAspNetCoreMeterTelemetryPrefix(...))
user_agent.present(counter)user_agent.missing(counter)
Export to OpenTelemetry / Application Insights
Collect via OpenTelemetry EventCounters instrumentation:
using OpenTelemetry.Metrics;
metrics.AddEventCountersInstrumentation(options =>
{
options.AddEventSources(HttpUserAgentParserAspNetCoreEventSource.EventSourceName);
});
Then export using your preferred exporter (OTLP, Prometheus, Azure Monitor / Application Insights, …).
Export native meters to OpenTelemetry
If you enabled native meters (see above), collect them via AddMeter(...):
using OpenTelemetry.Metrics;
metrics.AddMeter("mycsharp.http_user_agent_parser.aspnetcore");
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. net11.0 is compatible. |
-
net10.0
- MyCSharp.HttpUserAgentParser (>= 4.0.1)
-
net11.0
- MyCSharp.HttpUserAgentParser (>= 4.0.1)
-
net8.0
- MyCSharp.HttpUserAgentParser (>= 4.0.1)
-
net9.0
- MyCSharp.HttpUserAgentParser (>= 4.0.1)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on MyCSharp.HttpUserAgentParser.AspNetCore:
| Package | Downloads |
|---|---|
|
Zoo.GenericApp.Logic
Базовая логика для для приложения на Croco, включена поддержка Clt, Ecc, Doc, Js-Open-Api. Содержатся основные Background сервисы необходимые для работы веб-приложения. |
|
|
Wei.Abp.Identity.Session.AspNetCore
abp module |
|
|
IME.IdentityStore
Package Description |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on MyCSharp.HttpUserAgentParser.AspNetCore:
| Repository | Stars |
|---|---|
|
AscensionGameDev/Intersect-Engine
Intersect provides a complete game development suite for creating 2d mmorpgs with no programming experience required!
|
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.1 | 0 | 12/5/2026 |
| 3.1.6 | 112,170 | 4/1/2026 |
| 3.1.3 | 9,843 | 3/5/2026 |
| 3.0.28 | 93,274 | 8/25/2025 |
| 3.0.27 | 375 | 8/23/2025 |
| 3.0.25 | 27,975 | 4/26/2025 |
| 3.0.23 | 2,322 | 4/12/2025 |
| 3.0.21-gd594614d04 | 309 | 3/31/2025 |
| 3.0.20-g7795a06d24 | 291 | 3/20/2025 |
| 3.0.19-g3452a5347c | 227 | 3/15/2025 |
| 3.0.18-gbf6637cea6 | 1,944 | 3/2/2025 |
| 3.0.13 | 18,539 | 2/25/2025 |
| 3.0.13-g9ebf55cc61 | 258 | 2/25/2025 |
| 3.0.12 | 361 | 2/25/2025 |
| 3.0.12-g2db20cc097 | 915 | 1/25/2025 |
| 3.0.11 | 12,871 | 1/25/2025 |
| 3.0.11-gd806c9c385 | 238 | 1/14/2025 |
| 3.0.10 | 15,971 | 1/14/2025 |
| 1.0.0 | 163 | 2/19/2026 |