Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Requested browser name and version in asp.net core 2.0

How to get Requested browser name and version in asp.net core 2.0

How to get user Browser name ( user-agent ) in Asp.net Core? returns all the browser installed on client PC. But I need the browser name currently requesting.

enter image description here

like image 939
Md. Al-Amin Avatar asked Oct 16 '25 10:10

Md. Al-Amin


1 Answers

Use install-package Wangkanai.Detection -pre and install-package Wangkanai.Detection.Browser -pre in PM to install package. Then... Write the following code in Startup.cs:

services.AddDetection();
services.AddDetectionCore().AddBrowser();

In your Controller:

private readonly IDetection _detection;
        public HomeController(IDetection detection)
        {
            _detection = detection;
        }
public IActionResult Index()
        {
            string browser_info = _detection.Browser.Type.ToString() + _detection.Browser.Version;
            ViewData["a"] = browser_info;
            return View(_detection);
        }
like image 189
Abdelmomen Awad Avatar answered Oct 19 '25 00:10

Abdelmomen Awad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!