首页 > 代码库 > silverlight 用户浏览器未安装SL插件问题

silverlight 用户浏览器未安装SL插件问题

1.在Silverlight启动页面

 1 <%@ Page Language="C#" AutoEventWireup="true" %> 2  3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 4 <html xmlns="http://www.w3.org/1999/xhtml"> 5 <head runat="server"> 6     <title>SilverlightApplication9</title> 7     <style type="text/css"> 8         html, body { 9             height: 100%;10             overflow: auto;11         }12 13         body {14             padding: 0;15             margin: 0;16         }17 18         #silverlightControlHost {19             height: 100%;20             text-align: center;21         }22     </style>23     <script type="text/javascript" src=http://www.mamicode.com/"SplashScreen.js"></script>24     <script type="text/javascript" src=http://www.mamicode.com/"Silverlight.js"></script>25     <script type="text/javascript">26         function onSilverlightError(sender, args) {27             var appSource = "";28             if (sender != null && sender != 0) {29                 appSource = sender.getHost().Source;30             }31 32             var errorType = args.ErrorType;33             var iErrorCode = args.ErrorCode;34 35             if (errorType == "ImageError" || errorType == "MediaError") {36                 return;37             }38 39             var errMsg = "Silverlight 应用程序中未处理的错误 " + appSource + "\n";40 41             errMsg += "代码: " + iErrorCode + "    \n";42             errMsg += "类别: " + errorType + "       \n";43             errMsg += "消息: " + args.ErrorMessage + "     \n";44 45             if (errorType == "ParserError") {46                 errMsg += "文件: " + args.xamlFile + "     \n";47                 errMsg += "行: " + args.lineNumber + "     \n";48                 errMsg += "位置: " + args.charPosition + "     \n";49             }50             else if (errorType == "RuntimeError") {51                 if (args.lineNumber != 0) {52                     errMsg += "行: " + args.lineNumber + "     \n";53                     errMsg += "位置: " + args.charPosition + "     \n";54                 }55                 errMsg += "方法名称: " + args.methodName + "     \n";56             }57 58             throw new Error(errMsg);59         }60     </script>61 </head>62 <body>63     <form id="form1" runat="server" style="height: 100%">64         <div id="silverlightControlHost">65             <object data=http://www.mamicode.com/"data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">66                 <param name="source" value=http://www.mamicode.com/"ClientBin/SilverlightApplication9.xap" />67                 <param name="onError" value=http://www.mamicode.com/"onSilverlightError" />68                 <param name="initParams" value=http://www.mamicode.com/"<%= String.Format("{0}={1},{2}={3}","ClientIP", Request.UserHostAddress,"ClientName",Request.UserHostName) %>" />69                 <param name="background" value=http://www.mamicode.com/"white" />70                 <param name="minRuntimeVersion" value=http://www.mamicode.com/"5.0.61118.0" />71                 <param name="autoUpgrade" value=http://www.mamicode.com/"true" />72                 <a href=http://www.mamicode.com/"/DownloadSilverlight.aspx" style="text-decoration: none">73                 <img src=http://www.mamicode.com/"/Img/SLMedallion_CHS.png" alt="获取 Microsoft Silverlight"74                     style="border-style: none" />75             </a>76             </object>77             <iframe id="_sl_historyFrame" style="visibility: hidden; height: 0px; width: 0px; border: 0px"></iframe>78         </div>79     </form>80 </body>81 </html>
View Code

2.在Silverlight.web服务端添加要显示的图片及路径、silverlight插件的两个版本(32位、64位)

3.在silverlight.web服务端添加DownloadSilverlight.aspx项

 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Web; 5 using System.Web.UI; 6 using System.Web.UI.WebControls; 7  8 namespace SilverlightApplication9.Web 9 {10     public partial class DownloadSilverlight : System.Web.UI.Page11     {12         protected void Page_Load(object sender, EventArgs e)13         {14             //string info = "客户端IP:" + Page.Request.UserHostAddress;15             //info += "<br/>用户信息:" + Page.User;16             //info += "<br/>服务器电脑名称:" + Page.Server.MachineName;17             //info += "<br/>当前用户电脑名称:" + System.Net.Dns.GetHostName();18             //info += "<br/>当前电脑名:" + System.Environment.MachineName;19             //info += "<br/>当前电脑所属网域:" + System.Environment.UserDomainName;20             //info += "<br/>当前电脑用户:" + System.Environment.UserName;21             //info += "<hr/>";22             //info += "<br/>浏览器类型:" + Request.Browser.Browser;23             //info += "<br/>浏览器标识:" + Request.Browser.Id;24             //info += "<br/>浏览器版本号:" + Request.Browser.Version;25             //info += "<br/>浏览器是不是测试版本:" + Request.Browser.Beta;26             ////info += "<br/>浏览器的分辨率(像素):" + Request["width"].ToString() + "*" + Request["height"].ToString();//1280/102427             //info += "<hr/>";28             //info += "<br/>客户端的操作系统:" + Request.Browser.Platform;29             //info += "<br/>是不是win16系统:" + Request.Browser.Win16;30             //info += "<br/>是不是win32系统:" + Request.Browser.Win32;31             //Response.Write(info);32 33             //int loop1, loop2;34             //NameValueCollection coll;35 36             //// Load ServerVariable collection into NameValueCollection object.37             //coll = Request.ServerVariables;38             //// Get names of all keys into a string array. 39             //String[] arr1 = coll.AllKeys;40             //for (loop1 = 0; loop1 < arr1.Length; loop1++)41             //{42             //    Response.Write("Key: " + arr1[loop1] + "<br>");43             //    String[] arr2 = coll.GetValues(arr1[loop1]);44             //    for (loop2 = 0; loop2 < arr2.Length; loop2++)45             //    {46             //        Response.Write("Value " + loop2 + ": " + Server.HtmlEncode(arr2[loop2]) + "<br>");47             //    }48             //}49             //Response.End();50             if (Request.ServerVariables["HTTP_USER_AGENT"].ToString().Contains("WOW64"))51             {52                 Response.Redirect("/Silverlight/Silverlight_x64.exe");53             }54             else55             {56                 Response.Redirect("/Silverlight/Silverlight.exe");57             }58         }59     }60 }
View Code