Shyjus.BrowserDetector 1.0.6

There is a newer version of this package available.
See the version list below for details.
dotnet add package Shyjus.BrowserDetector --version 1.0.6
NuGet\Install-Package Shyjus.BrowserDetector -Version 1.0.6
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="Shyjus.BrowserDetector" Version="1.0.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Shyjus.BrowserDetector --version 1.0.6
#r "nuget: Shyjus.BrowserDetector, 1.0.6"
#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 Shyjus.BrowserDetector as a Cake Addin
#addin nuget:?package=Shyjus.BrowserDetector&version=1.0.6

// Install Shyjus.BrowserDetector as a Cake Tool
#tool nuget:?package=Shyjus.BrowserDetector&version=1.0.6

This package adds browser detection, device detection and operating system capabilities capabilities in asp.net core apps.

This library detects

  1. Browser
  2. Device type
  3. Operating System

.NET framework 4.7 has Browser property on HttpContext.Request which gives you information about the browser, from where there HTTP request came from. Unfortunately, ASP.NET core does not have this. This package can be used for browser & device detection in your ASP.NET core apps.

How to use ?

Step 1: Install the BrowserDetector nuget package

Install-Package Shyjus.BrowserDetector

Step 2: Enable the browser detection service inside the ConfigureServices method of Startup.cs.

public void ConfigureServices(IServiceCollection services)
{
    // Add browser detection service
    services.AddBrowserDetection();

    services.AddMvc();
}

Step 3: Inject IBrowserDetector to your controller class or view file or middleware and access the Browser property.

Example usage in controller code

public class HomeController : Controller
{
    private readonly IBrowserDetector browserDetector;
    public HomeController(IBrowserDetector browserDetector)
    {
        this.browserDetector = browserDetector;
    }
    public IActionResult Index()
    {
        var browser = this.browserDetector.Browser;
        // Use browser object as needed.

        return View();
    }
}

Example usage in view code

@inject Shyjus.BrowserDetector.IBrowserDetector browserDetector

<h2> @browserDetector.Browser.Name </h2>
<h3> @browserDetector.Browser.Version </h3>
<h3> @browserDetector.Browser.OS </h3>
<h3> @browserDetector.Browser.DeviceType </h3>

Example usage in custom middlware

You can inject the IBrowserDetector to the InvokeAsync method.

public class MyCustomMiddleware
{
    private RequestDelegate next;
    public MyCustomMiddleware(RequestDelegate next)
    {
        this.next = next;
    }
    public async Task InvokeAsync(HttpContext httpContext, IBrowserDetector browserDetector)
    {
        var browser = browserDetector.Browser;

        if (browser.Type == BrowserType.Edge)
        {
            await httpContext.Response.WriteAsync("Have you tried the new chromuim based edge ?");
        }
        else
        {
            await this.next.Invoke(httpContext);
        }
    }
}

Browsers supported

First Header Operating System Device type
Chrome Windows Desktop
Chrome Mac OS Desktop
Chrome iOS Mobile
Chrome iOS Tablet
Chrome Android Mobile
Internet Explorer 11 Windows Desktop
Edge Windows Desktop
Edge OSX Desktop
Edge iOS Tablet
EdgeChromium Windows Desktop
EdgeChromium OSX Desktop
Opera Windows Desktop
Opera Mac OS Desktop
Opera iOS Mobile
Opera iOS Tablet
Safari Windows Desktop
Safari Mac OS Desktop
Safari iOS Mobile
Safari iOS Tablet
Firefox Windows Desktop
Firefox Mac OS Desktop
Firefox iOS Mobile
Firefox iOS Tablet

If you do not see a specific browser/os/device type combo, please open an issue

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (7)

Showing the top 5 NuGet packages that depend on Shyjus.BrowserDetector:

Package Downloads
MosFlightWidget.Helper

Package Description

SeedBt.Library.Core

Package Description

MosFlightWidgetHelper

Package Description

Yaroslav08.Extensions

Package Description

LogusBrain.Core

An easy to use library with all the features you need.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Shyjus.BrowserDetector:

Repository Stars
xianhc/apevolo-api
基于 .Net 8 、SqlSugar、Vue、RBAC、前后端分离的开箱即用的企业级中后台管理系统
Version Downloads Last updated
3.0.0-preview2 134 1/2/2024
2.0.0 483,189 5/23/2021
1.1.1 189,733 2/19/2020
1.1.0 743 2/19/2020
1.0.9 1,003 1/24/2020
1.0.8 11,181 9/13/2019
1.0.7 503 9/7/2019
1.0.6 497 9/7/2019
1.0.5 495 8/31/2019
1.0.4 515 8/30/2019
1.0.3 520 8/30/2019
1.0.2 484 8/30/2019
1.0.1 493 8/30/2019
1.0.0 581 8/30/2019