开发者

Get Current Client Silverlight Version?

I want to know if there is a way of using C# to get the Current Silverlight Version a user is running when opening a client of an app I'm developing.

It is for logging purposes.

I want to know if they are using Silverlight 3 or 4 on their browse开发者_运维技巧rs


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜