ASP.NET:Chrome 浏览器检测不一致
我正在 2 台计算机上测试 ASP.NET 3.5 应用程序:一台是 Windows 7 x64,另一台是 Windows Server 2008 x64。
当我使用同一个 Chrome 实例在这两台计算机上打开网站时,我在 HttpBrowserCapability.Browser
上得到不同的结果:在 Windows 7 计算机上,我得到 browser.Name = "appleMac-safari "
,在 Windows Server 计算机上,我得到 browser.Name = "applewebkit"
。
两台机器都安装了相同的(据我所知)asp.net 应用程序、相同的 machine.config 文件,并且 C 上的 *.browser 文件也相同:\Windows\Microsoft.NET\Framework64\v2.0.50727\CONFIG\Browsers
你知道为什么会出现这种差异吗?
I am testing an ASP.NET 3.5 app on 2 machines: one is a Windows 7 x64, and the other Windows Server 2008 x64.
When I use the same Chrome instance to open the websites on these 2 machines, I get different results on HttpBrowserCapabilities.Browser
: on the Windows 7 machine I get browser.Name = "appleMac-safari"
, while on the Windows Server machine I get browser.Name = "applewebkit"
.
Both machine are have identical (AFAIK) installations of the asp.net app, same machine.config
files, and the *.browser
files are also identical on C:\Windows\Microsoft.NET\Framework64\v2.0.50727\CONFIG\Browsers
Any ideas why this discrepancy happens?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用以下内容来检测 Chrome,因为它更可靠
其中 UserAgent 值是:
Use the following to detect Chrome as it is more reliable
Where the UserAgent Value is:
我会查看浏览器发送的用户代理字符串。很可能,这两个平台上该版本的 Chrome 中的用户代理字符串不同。有很多细微的差别。
另外,我想补充一点,在大多数情况下,服务器端浏览器嗅探的用途非常有限,因为正如您所见,它不是特别可靠并且很容易被伪造。如果您希望以不同的方式设计样式或调整某些客户端行为,请使用 Modernizr 之类的 javascript 包来完成特征检测是一种更稳健的方法。
I would look at the user agent string the browser is sending in. Chances are, the user agent string is not the same in that version of chrome on those 2 platforms. There are lots of little differences.
Also, I would add that, in most cases, server-side browser sniffing has very limited uses because, as you have seen, it is not particularly reliable and can be easily faked. If you are looking to style things differently or tweak some client-side behavior, using a javascript package like Modernizr to do feature detection is a much more robust way to go.