MyCSharp.HttpUserAgentParser
4.0.1
Requires NuGet 2.12 or higher.
dotnet add package MyCSharp.HttpUserAgentParser --version 4.0.1
NuGet\Install-Package MyCSharp.HttpUserAgentParser -Version 4.0.1
<PackageReference Include="MyCSharp.HttpUserAgentParser" Version="4.0.1" />
<PackageVersion Include="MyCSharp.HttpUserAgentParser" Version="4.0.1" />
<PackageReference Include="MyCSharp.HttpUserAgentParser" />
paket add MyCSharp.HttpUserAgentParser --version 4.0.1
#r "nuget: MyCSharp.HttpUserAgentParser, 4.0.1"
#:package MyCSharp.HttpUserAgentParser@4.0.1
#addin nuget:?package=MyCSharp.HttpUserAgentParser&version=4.0.1
#tool nuget:?package=MyCSharp.HttpUserAgentParser&version=4.0.1
MyCSharp.HttpUserAgentParser
Fast HTTP User-Agent parsing for .NET.
- Allocation-free detection with vectorized searches (
SearchValues<string>on .NET 9+) and a 128-bit shared rule index;ReadOnlySpan<char>overloads including zero-allocationTryGetBrowser(ReadOnlySpan<char>, out string?, out ReadOnlySpan<char>); no regular expressions in the parser - Trimming and Native AOT compatible
- Detects browsers and in-app WebViews including Amazon Silk, DuckDuckGo, Whale, QQ Browser, Huawei Browser, Miui Browser, Instagram and Facebook (
FBAV), and search, SEO and AI crawlers including Bravebot, Screaming Frog SEO Spider, KimiBot, DeepSeekBot, ChatGLM-Spider and OAI-AdsBot
Repository: https://github.com/mycsharp/HttpUserAgentParser
Install
dotnet add package MyCSharp.HttpUserAgentParser
Quick start (no DI)
string userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36";
HttpUserAgentInformation info = HttpUserAgentParser.Parse(userAgent);
// or: HttpUserAgentInformation.Parse(userAgent)
Regular expressions
The parser itself does not execute regular expressions. HttpUserAgentStatics.Platforms, HttpUserAgentStatics.Browsers
and HttpUserAgentPlatformInformation.Regex provide source-generated regular expressions ([GeneratedRegex]) for your own
matching; the browser regexes are created when HttpUserAgentStatics is first used, a platform regex on first access. They use RegexOptions.IgnoreCase with culture-invariant case mapping and
no RegexOptions.Compiled, because the source generator already emits the matching code.
Native AOT
The package is trimming and Native AOT compatible. EventCounters (WithTelemetry()) need
<EventSourceSupport>true</EventSourceSupport> in Native AOT apps; native meters work without it.
Dependency injection
If you want to inject a parser (e.g., in ASP.NET Core), use IHttpUserAgentParserProvider.
No cache
services
.AddHttpUserAgentParser();
ConcurrentDictionary cache
services
.AddHttpUserAgentCachedParser(); // default limit: 10,000 entries
// or: .AddHttpUserAgentCachedParser(maxCacheEntries: 4096);
// or: .AddHttpUserAgentParser<HttpUserAgentParserCachedProvider>();
HttpUserAgentParserCachedProvider bounds memory usage by rotating the cache atomically once MaxCacheEntries
(default: HttpUserAgentParserCachedProvider.DefaultMaxCacheEntries = 10_000) is reached; it has no sliding/absolute expiration.
The key is the exact user agent string (ordinal). For web applications that need expiration or fine-grained eviction policies, use
MyCSharp.HttpUserAgentParser.MemoryCache.
All DI registration extensions are idempotent (TryAddSingleton).
Telemetry (EventCounters)
Telemetry is:
- Opt-in: disabled by default (keeps hot path overhead-free)
- Low overhead: counters are only written when a listener is attached
Enable telemetry (Fluent API)
services
.AddHttpUserAgentParser()
.WithTelemetry();
EventSource + counters
EventSource: MyCSharp.HttpUserAgentParser (constant: HttpUserAgentParserEventSource.EventSourceName)
parse-requests(incrementing)parse-duration(s, event counter)cache-hit(incrementing,HttpUserAgentParserCachedProvider)cache-miss(incrementing,HttpUserAgentParserCachedProvider)cache-size(polling,HttpUserAgentParserCachedProvider): the entries of all live providers of the package, including entries cached before telemetry was enabled
Monitor with dotnet-counters
dotnet-counters monitor --process-id <pid> MyCSharp.HttpUserAgentParser
Telemetry (native Meters)
In addition to EventCounters, this package can emit native System.Diagnostics.Metrics instruments.
Telemetry is:
- Opt-in: disabled by default (keeps hot path overhead-free)
- Low overhead: measurements are only recorded when enabled
Enable meters (Fluent API)
services
.AddHttpUserAgentParser()
.WithMeterTelemetry();
Pass your own Meter to WithMeterTelemetry(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.
The core and the MemoryCache package need separate meters (both create cache.hit, cache.miss and cache.size, and a meter keeps
its instruments): a meter that one of them has used is rejected by the other with an ArgumentException, also after a switch.
Meter + instruments
Meter: mycsharp.http_user_agent_parser (the prefix mycsharp. can be changed with WithMeterTelemetryPrefix(...))
parse.requests(counter)parse.duration(histogram, s)cache.hit(counter)cache.miss(counter)cache.size(observable gauge): the entries of all live providers of the package, including entries cached before telemetry was enabled
Export to OpenTelemetry
You can collect these EventCounters via OpenTelemetry metrics and export them (OTLP, Prometheus, Azure Monitor, …).
Packages you typically need:
OpenTelemetryOpenTelemetry.Exporter.OpenTelemetryProtocol(or another exporter)OpenTelemetry.Instrumentation.EventCounters
Example (minimal):
using OpenTelemetry.Metrics;
using MyCSharp.HttpUserAgentParser.Telemetry;
builder.Services.AddOpenTelemetry()
.WithMetrics(metrics =>
{
metrics
.AddEventCountersInstrumentation(options =>
{
options.AddEventSources(HttpUserAgentParserEventSource.EventSourceName);
})
.AddOtlpExporter();
});
If you also use the MemoryCache/AspNetCore packages, add their EventSource names too.
Export native meters to OpenTelemetry
If you enabled native meters (see above), collect them via AddMeter(...):
using OpenTelemetry.Metrics;
builder.Services.AddOpenTelemetry()
.WithMetrics(metrics =>
{
metrics
.AddMeter("mycsharp.http_user_agent_parser")
.AddOtlpExporter();
});
Export to Application Insights
There are two common approaches:
1) Recommended: OpenTelemetry → Application Insights
Collect with OpenTelemetry (see above) and export to Azure Monitor / Application Insights using an Azure Monitor exporter. This keeps your pipeline consistent and avoids custom listeners.
Typical packages (names may differ by version):
OpenTelemetryOpenTelemetry.Instrumentation.EventCountersAzure.Monitor.OpenTelemetry.Exporter
2) Custom EventListener → TelemetryClient
If you prefer a direct listener, you can attach an EventListener and forward values as custom metrics.
High-level idea:
- Enable the EventSource
- Parse the
EventCounterspayload - Track as Application Insights metrics
Notes:
- This is best-effort telemetry (caches can race)
- Keep aggregation intervals reasonable (e.g. 10s)
| 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
-
net11.0
- No dependencies.
-
net8.0
-
net9.0
NuGet packages (20)
Showing the top 5 NuGet packages that depend on MyCSharp.HttpUserAgentParser:
| Package | Downloads |
|---|---|
|
Volo.Abp.AspNetCore
Package Description |
|
|
MyCSharp.HttpUserAgentParser.AspNetCore
HTTP User Agent Parser Extensions for ASP.NET Core |
|
|
MyCSharp.HttpUserAgentParser.MemoryCache
HTTP User Agent Parser Extensions for IMemoryCache |
|
|
ZhileTime.Hope.AspNetCore
ASP.NET Core integration infrastructure for HOPE applications. |
|
|
PostalApiClient
Api client for mail delivery platform Postal |
GitHub repositories (2)
Showing the top 2 popular GitHub repositories that depend on MyCSharp.HttpUserAgentParser:
| Repository | Stars |
|---|---|
|
abpframework/abp
Open-source web application framework for ASP.NET Core! Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
|
|
|
sensslen/nuget-license
.NET Core tool to print or save all the licenses of a project
|
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.1 | 92 | 12/5/2026 |
| 3.1.6 | 319,163 | 4/1/2026 |
| 3.1.3 | 54,523 | 3/5/2026 |
| 3.0.28 | 2,404,595 | 8/25/2025 |
| 3.0.27 | 906 | 8/23/2025 |
| 3.0.25 | 1,285,300 | 4/26/2025 |
| 3.0.23 | 20,504 | 4/12/2025 |
| 3.0.13 | 71,015 | 2/25/2025 |
| 3.0.12 | 755 | 2/25/2025 |
| 3.0.11 | 55,595 | 1/25/2025 |
| 3.0.10 | 27,663 | 1/14/2025 |