我想在 .net-core 中使用 HttpBrowserCapabilities
,我尝试了以下方法:
var userAgent = httpContext.Request.Headers["user-agent"];
var userBrowser = new HttpBrowserCapabilities { Capabilities = new Hashtable { { string.Empty, userAgent } } };
var factory = new BrowserCapabilitiesFactory();
factory.ConfigureBrowserCapabilities(new NameValueCollection(), userBrowser);
var mobileString = userBrowser.IsMobileDevice ? "(mobil)" : string.Empty;
var browserString = $"{userBrowser.Browser} version {userBrowser.Version} {mobileString} OS: {userBrowser.Platform}";
但是会抛出一个InvalidCastException异常。我该如何让这段代码返回正确的值?
First()
而不是ToArray()[0]
,这样行吗? - Lloyd