问题描述:

Is there anyway to check from a website if a client has a specific version of .Net installed and which one it is so you can offer them different downloads based on it?

网友答案:

You can parse the user agent. There is MSDN page that describes the format, especially, take a look at the .NET CLR <version> token.

However, you can guarantee the information will be present and accurate : non MS browser, customized user agent string, paranoid user agent, etc. can be factors for users to remove such information.

[Edit] Probably not an easy things to do, but you can use a setup bootstrapper which will detect the installed version to download the actual setup. Microsoft use this technique for some of their products web installers.

网友答案:

Some browsers include this information in the User Agent header, eg. from the log files on a machine with IE8 installed:

Mozilla/4.0+(compatible;+MSIE+8.0;+Windows+NT+6.0;+Trident/4.0;+SLCC1;+.NET+CLR+2.0.50727;+.NET+CLR+3.0.30729;+.NET+CLR+3.5.30729;+.NET4.0C;+.NET4.0E)

However this information is not included in IE9's user agent string.

In general: without trying something on the client you cannot be sure.

网友答案:

I discovered this issue recently and IE9 when standards mode doesn't include the CLR versions in the User Agent, as noted in Richard's answer. It seems the only way to get this information server-side is setting compatibility view mode. Alternatively if you wish to preserve standards mode then you will need to get the information via java script.

if (navigator.userAgent.match(/\.NET CLR [234].[05]/)) {
    // do stuff depending on presence
}

You can adjust the version numbers or drop off that bit depending on your needs.

相关阅读:
Top