您的位置:首页 > 职场人生

综合应用WPF/WCF/WF/LINQ之十八:检测客户端是否安装有.NET 3.0

2008-01-11 20:52 495 查看
 为了在运行XBAP程序之前,有一个检测客户端是否安装有.NET 3.0的机会,我们才不让用户直接访问Eallies.OA.UI.xbap文件,而是先访问一个Default.htm文件(当然,另外一个原因是网站的默认启动页面中包含这个文件名)。
  Default.htm文件的内容如下,如果通过检测,则跳转到Eallies.OA.UI.xbap文件;否则弹出了一个警告对话框,当然,您也可以更改得更好,让程序自动去下载并安装.NET 3.0.
  另外,如果客户端安装的是.NET 3.0测试版,则版本号有可能不是3.0.04506,您也可以对这个程序进行改造,让程序支持多个版本的.NET 3.0。

1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml" >
3 <head>
4 <title>Eallies OA</title>
5 <script language="javascript" type="text/javascript">
6 <!--
7 var strRuntimeVersion = "3.0.04506";
8
9 function CheckVersion()
10 {
11 if (HasRuntimeVersion(strRuntimeVersion) == false)
12 {
13 alert("This machine does not have correct version of .NET Framework 3.0 Runtime.");
14
15 return false;
16 }
17
18 return true;
19 }
20
21 //
22 // Retrieve the version from the user agent string and compare
23 // with specified version.
24 //
25 function HasRuntimeVersion(version)
26 {
27 var userAgentString = navigator.userAgent.match(/.NET CLR [0-9.]+/g);
28
29 if (userAgentString != null)
30 {
31 for (var i = 0; i < userAgentString.length; ++i)
32 {
33 if (Compare(this.GetVersion(version), this.GetVersion(userAgentString[i])) <= 0) return true;
34 }
35 }
36
37 return false;
38 }
39
40 //
41 // Extract the numeric part of the version string.
42 //
43 function GetVersion(versionString)
44 {
45 var numericString = versionString.match(/([0-9]+)\.([0-9]+)\.([0-9]+)/i);
46
47 return numericString.slice(1);
48 }
49
50 //
51 // Compare the 2 version strings by converting them to numeric format.
52 //
53 function Compare(version1, version2)
54 {
55 for (var i = 0; i < version1.length; ++i)
56 {
57 var number1 = new Number(version1[i]);
58 var number2 = new Number(version2[i]);
59
60 if (number1 < number2) return -1;
61 if (number1 > number2) return 1;
62 }
63
64 return 0;
65 }
66 -->
67 </script>
68 </head>
69 <body>
70 <script language="javascript" type="text/javascript">
71
72 if (CheckVersion() == true)
73 {
74 document.location.href = "Eallies.OA.UI.xbap";
75 }
76
77 </script>
78 </body>
79 </html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐