如何在asp.net core 2.0中获取请求的浏览器名称和版本
如何在Asp.net Core中获取用户浏览器名称(user-agent)?返回客户端PC上安装的所有浏览器。
但我需要当前请求的浏览器名称。
使用PM中的install-package Wangkanai.Detection -pre
和install-package Wangkanai.Detection.Browser -pre
来安装包。
然后,在Startup.cs中编写以下代码:
services.AddDetection();
services.AddDetectionCore().AddBrowser();
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);
}
尝试这个 Request.Headers["User-Agent"].ToString()