Shyjus.BrowserDetector 1.1.1

Browser detection, device detection and operating system detection capabilities in asp.net core.

Install-Package Shyjus.BrowserDetector -Version 1.1.1
dotnet add package Shyjus.BrowserDetector --version 1.1.1
<PackageReference Include="Shyjus.BrowserDetector" Version="1.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Shyjus.BrowserDetector --version 1.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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

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

Release Notes

Signing the assembly.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.1.1 9,338 2/19/2020
1.1.0 121 2/19/2020
1.0.9 366 1/24/2020
1.0.8 7,034 9/13/2019
1.0.7 121 9/7/2019
1.0.6 123 9/7/2019
1.0.5 114 8/31/2019
1.0.4 114 8/30/2019
1.0.3 110 8/30/2019
1.0.2 105 8/30/2019
1.0.1 104 8/30/2019
1.0.0 114 8/30/2019