0
我想在.net-core中使用HttpBrowserCapabilities
。我試過以下方法:.Net-Core從httpContext獲取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。我怎樣才能讓這段代碼重新獲得正確的值?
而不是'ToArray的()[0]''將第一()'不工作? – Lloyd
ty :) :)你是對的 – osanger