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.
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.
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);
}
Try this Request.Headers["User-Agent"].ToString()