检测没有 UserAgent 字符串的 .NET 版本
大多数现代浏览器(Chrome 10、Firefox 4、IE9)都在缩短其 UserAgent 标识符。因此,受支持的 .NET 版本不再发送到服务器。
为了让我们的客户能够使用我们的ClickOnce应用程序,我们需要知道客户端支持哪些框架。
Chrome 和 Firefox ClickOnce 帮助程序的 Javascript 检测是一个开始(这些现在在 Firefox 4 中失败),但我们不再有办法检测客户端是否安装了 .NET 2.0、3.5 或 4.0。
除了从 UserAgent 字符串检测 Windows 平台并推断最可能的框架(XP = 1.1、Vista=2.0、Win7=3.5)之外,我们如何检测 .NET 框架支持?
(我们希望阻止 .application 文件下载,因为我们的大多数客户似乎没有注意到下载“弹出式广告”)
Most modern browsers (Chrome 10, Firefox 4, IE9) are all shortening their UserAgent identifiers. As a result, the supported .NET versions are no longer sent to the server.
In order to allow our customers to use our ClickOnce application, we need to know which frameworks are supported by the client.
Javascript detection of the Chrome and Firefox ClickOnce helpers are a start (these are now failing in Firefox 4), but we no longer have a way of detecting if the client has .NET 2.0, 3.5 or 4.0 installed.
Barring from detecting the Windows platform from the UserAgent string and inferring the most likely framework (XP = 1.1, Vista=2.0, Win7=3.5), how could we detect .NET framework support?
(We want to prevent the .application file downloading as most of our clients don't seem to notice the downloading "pop-unders")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
navigator.userAgent 至少在 IE9 上为您提供扩展的 UA 字符串
navigator.userAgent gives you the extended UA string at least on IE9
此问题是 由 Microsoft 修复。 .NET 版本现在作为 HTTP 请求标头“X-ClickOnceSupport”返回。
在 PHP 中,您可以通过 getenv() 获得此值。
在 Perl 中,
在 JavaScript 中这是不可能的,根据 这个答案。
(这一切都是从检查 Firefox .NET Assistant 的代码开始的,这让我搜索了“X-ClickOnceSupport”标头。没有什么比查看源代码来解开谜团更好的了!)
This problem was fixed by Microsoft. The .NET version is now returned as an HTTP request header, "X-ClickOnceSupport".
In PHP, you would get this via getenv()
In Perl
In JavaScript it is not possible, according to this answer.
(This all started by examining the code of the Firefox .NET Assistant, which led me to search for the "X-ClickOnceSupport" header. Nothing like being able to view the source code to solve a mystery!)
我看不出有什么办法可以做到这一点。如果浏览器没有告诉您的服务器安装了哪些框架,那么您没有任何其他方法可以找到。
I don't see a way to do this. If the browser doesn't tell your server which frameworks are installed then you don't have any other way to find out.
我解决这个问题的方法是发回一个响应标头,告诉浏览器以兼容性方式运行,然后在 navigator.userAgent 上使用 javascript 检测框架版本。
页面代码隐藏:
页面上的 Javascript
The way I got around this problem was to send back a response header telling the browser to function in compatibility then detecting the framework version with javascript on the navigator.userAgent.
Page Code-behind:
Javascript on the page