Md. Al-Amin
Md. Al-Amin

Reputation: 51

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

Upvotes: 4

Views: 9254

Answers (2)

Abdelmomen Awad
Abdelmomen Awad

Reputation: 87

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

Upvotes: 3

Parth Patel
Parth Patel

Reputation: 3997

Try this Request.Headers["User-Agent"].ToString()

Upvotes: -1

Related Questions