The extensible library that uses client hints and user agent to detect browser, device, platform and architecture.
Install-Package Optivify.BrowserDetection
var builder = WebApplication.CreateBuilder(args);
var services = builder.Services;
var configuration = builder.Configuration;
// Add browser detection
services.AddBrowserDetection(configuration);
Use the service in controller:
public class HomeController : Controller
{
private readonly IDetectionService detectionService;
public HomeController(IDetectionService detectionService)
{
this.detectionService = detectionService;
}
public IActionResult Index()
{
var browserName = this.detectionService.Browser.Name;
var browserVersion = this.detectionService.Browser.Version;
return View();
}
}
Use the service in view:
@using Optivify.BrowserDetection.Services
@inject IDetectionService detectionService
@detectionService.Browser.Name
You can find the sample project in the folder src/Samples/Optivify.BrowserDetection.Samples.Web.AspNetCore. The online detection: https://detection.optivify.com