![]() |
VOOZH | about |
dotnet add package UAParser.Core --version 4.0.5
NuGet\Install-Package UAParser.Core -Version 4.0.5
<PackageReference Include="UAParser.Core" Version="4.0.5" />
<PackageVersion Include="UAParser.Core" Version="4.0.5" />Directory.Packages.props
<PackageReference Include="UAParser.Core" />Project file
paket add UAParser.Core --version 4.0.5
#r "nuget: UAParser.Core, 4.0.5"
#:package UAParser.Core@4.0.5
#addin nuget:?package=UAParser.Core&version=4.0.5Install as a Cake Addin
#tool nuget:?package=UAParser.Core&version=4.0.5Install as a Cake Tool
This is the ASP.NET Core implementation of ua-parser.
The implementation uses the shared regex patterns and overrides from regexes.yaml (found in uap-core). The assembly embeds the latest regex patterns (enabled through a node module) which are loaded into the default parser. You can create a parser with more updated regex patterns by using the static methods on Parser to pass in specific patterns in yaml format.
You can then build and run the tests by
> dotnet restore UAParser.Core.sln
> dotnet test UAParser.Core.sln
To pull the latest regexes into the project:
> npm install && grunt
Step 1: Install the UAParser.Core nuget package
> Install-Package UAParser.Core
Step 2: Enable the browser detection service inside the ConfigureServices method of Startup.cs.
public void ConfigureServices(IServiceCollection services)
{
// Add user agent service
services.AddUserAgentParser();
services.AddMvc();
}
Step 3: Inject IUserAgentParser to your controller class or view file or middleware and access the ClientInfo property.
Example usage in controller code
public class HomeController : Controller
{
private readonly IUserAgentParser userAgentParser;
public HomeController(IUserAgentParser parser)
{
this.userAgentParser = parser;
}
public IActionResult Index()
{
var clientInfo = this.userAgentParser.ClientInfo;
// Use ClientInfo object as needed.
return View();
}
}
Example usage in view code
@inject UAParser.Interfaces.IUserAgentParser parser
<h2> @parser.ClientInfo.Browser.Family </h2>
<h3> @parser.ClientInfo.Browser.Version </h3>
<h3> @parser.ClientInfo.OS.ToString() </h3>
<h3> @parser.ClientInfo.Device.ToString() </h3>
Example usage in custom middlware
You can inject the IUserAgentParser to the InvokeAsync method.
public class MyCustomMiddleware
{
private RequestDelegate next;
public MyCustomMiddleware(RequestDelegate next)
{
this.next = next;
}
public async Task InvokeAsync(HttpContext httpContext, IUserAgentParser parser)
{
var clientInfo = parser.ClientInfo;
if (clientInfo.Browser.Family == "Edge")
{
await httpContext.Response.WriteAsync("Have you tried the new chromuim based edge ?");
}
else
{
await this.next.Invoke(httpContext);
}
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 5 NuGet packages that depend on UAParser.Core:
| Package | Downloads |
|---|---|
|
TJC.Cyclops.Common
企服版框架工具类项目,三方引用包主要有:Encrypt.Library、HtmlAgilityPack、ICSharpCode.SharpZipLib、log4net、Newtonsoft.Json、NPOI、SkiaSharp、ZXing等 |
|
|
CodePackage.UserData
Makes your life easier. |
|
|
YAFNET.Core
YAF.NET Core Library. |
|
|
SapphireLib.Tools
Package Description |
|
|
RuoYi.Framework
Package Description |
Showing the top 1 popular GitHub repositories that depend on UAParser.Core:
| Repository | Stars |
|---|---|
|
YAFNET/YAFNET
🌐 YAF.NET - C# ASP.NET Forum
|