UAParser.Core 4.0.3

dotnet add package UAParser.Core --version 4.0.3
NuGet\Install-Package UAParser.Core -Version 4.0.3
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="UAParser.Core" Version="4.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add UAParser.Core --version 4.0.3
#r "nuget: UAParser.Core, 4.0.3"
#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.
// Install UAParser.Core as a Cake Addin
#addin nuget:?package=UAParser.Core&version=4.0.3

// Install UAParser.Core as a Cake Tool
#tool nuget:?package=UAParser.Core&version=4.0.3

UserAgent Parser (based on ua_parser C# Library)

This is the ASP.NET Core implementation of ua-parser.

NuGet

build dotnet

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.

Build and Run Tests


You can then build and run the tests by

dotnet restore UAParser.Core.sln

dotnet test UAParser.Core.sln

Update the embedded regexes

To pull the latest regexes into the project:

    npm install
	grunt

How to use ?

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);
        }
    }
}

Authors:

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on UAParser.Core:

Package Downloads
YAFNET.Core

YAF.NET Core Library.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on UAParser.Core:

Repository Stars
YAFNET/YAFNET
🌐 YAF.NET - C# ASP.NET Forum
Version Downloads Last updated
4.0.3 7,536 10/21/2023
4.0.2 9,025 7/24/2023
4.0.1 628 7/22/2023
4.0.0 610 7/22/2023