Get Current Client Silverlight Version?

三世轮回 提交于 2019-12-04 11:56:51
var dotNetRuntimeVersion = Deployment.Current.RuntimeVersion;
var silverlightVersion = Environment.Version.ToString();

Supported in: 5, 4, 3

Using C# only I don't know, but what you could do is detect it with javascript and then send an ajax request to a function which lets the server know what version.

http://www.apijunkie.com/APIJunkie/blog/post/2009/04/How-to-programmatically-detect-Silverlight-version.aspx

The script above needs a bit of modifications to work with 4.0 but it should be easy enough.

Environment.Version might differ from plugin version. When I was using Silverlight 4 I managed to find version which had differ in major from plugin version and it seem there was no regularity.

There is way to get Silverlight Plugin version from JS and there is way to add JS to page and invoke it from Silverlight. So with code from here: http://www.visiblox.com/blog/posts/2010/04/29/determining-silverlight-version-installed/ I managed to do it this way:

var pScriptElement = HtmlPage.Document.CreateElement("script");
pScriptElement.SetAttribute("type", "text/javascript");
pScriptElement.SetProperty("text", "function GetSilverlightVersion(){var parts = Array(\"ver-major\", \"ver-minor\", \"ver-build\", \"ver-revision\");var nav = navigator.plugins[\"Silverlight Plug-In\"];var versionStr = \"\";if (nav) {versionStr = nav.description;} else {if(SilverlightIsInstalledOnIE)versionStr = GetSilverlightVersionOnIE();else versionStr = -1;}return versionStr;}function SilverlightIsInstalledOnIE(version){if(version == null)version = \"1.0\";var AgControl = new ActiveXObject(\"AgControl.AgControl\");    if(AgControl == null)return false;elsereturn AgControl.isVersionSupported(version);}function GetSilverlightVersionOnIE(){var currVersion = Array(1,0,0,0);for(var i=0;i<currVersion.length;i++){currVersion[i] = FindSupportedMaxVersionOnIE(currVersion, i,0,10000000);}return GetVersionString(currVersion);}function GetVersionString(versionArr,currVersion,index){if(index == null)index = -1;var versionStr = \"\";for(var i=0;i<versionArr.length;i++){if(i>0)versionStr += \".\";if(i==index)versionStr +=currVersion;elseversionStr += versionArr[i];}return versionStr;}function FindSupportedMaxVersionOnIE(versionArr, index,bottom,top){if(bottom >= top){return bottom;}var currVersion = bottom;var prevVersion = currVersion;var step = 1;while(currVersion<top){if(SilverlightIsInstalledOnIE(GetVersionString(versionArr,currVersion,index))){prevVersion = currVersion;currVersion += step;step *= 2;}elsereturn FindSupportedMaxVersionOnIE(versionArr, index,prevVersion,currVersion-1)}if(SilverlightIsInstalledOnIE(GetVersionString(versionArr,top,index)))return top;elsereturn FindSupportedMaxVersionOnIE(versionArr, index,prevVersion,top-1)}");
HtmlPage.Document.Body.AppendChild(pScriptElement);

var slVer = HtmlPage.Window.Invoke("GetSilverlightVersion", null);

This way I was able to get reliable plugin version on IE and other browsers. I've created my own class for parsing and comparing versions so I can easily check if user is using plugin from before fixes or with known malfunction.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!