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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MyCSharp.HttpUserAgentParser" Version="4.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MyCSharp.HttpUserAgentParser" Version="4.0.1" />
                    
Directory.Packages.props
<PackageReference Include="MyCSharp.HttpUserAgentParser" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MyCSharp.HttpUserAgentParser --version 4.0.1
                    
#r "nuget: MyCSharp.HttpUserAgentParser, 4.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MyCSharp.HttpUserAgentParser@4.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MyCSharp.HttpUserAgentParser&version=4.0.1
                    
Install as a Cake Addin
#tool nuget:?package=MyCSharp.HttpUserAgentParser&version=4.0.1
                    
Install as a Cake Tool

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-allocation TryGetBrowser(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:

  • OpenTelemetry
  • OpenTelemetry.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:

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):

  • OpenTelemetry
  • OpenTelemetry.Instrumentation.EventCounters
  • Azure.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 EventCounters payload
  • Track as Application Insights metrics

Notes:

  • This is best-effort telemetry (caches can race)
  • Keep aggregation intervals reasonable (e.g. 10s)
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
Loading failed