Detecting .NET version without UserAgent string

4.5k views Asked by At

Most modern browsers (Chrome 10, Firefox 4, IE9) are all shortening their UserAgent identifiers. As a result, the supported .NET versions are no longer sent to the server.

In order to allow our customers to use our ClickOnce application, we need to know which frameworks are supported by the client.

Javascript detection of the Chrome and Firefox ClickOnce helpers are a start (these are now failing in Firefox 4), but we no longer have a way of detecting if the client has .NET 2.0, 3.5 or 4.0 installed.

Barring from detecting the Windows platform from the UserAgent string and inferring the most likely framework (XP = 1.1, Vista=2.0, Win7=3.5), how could we detect .NET framework support?

(We want to prevent the .application file downloading as most of our clients don't seem to notice the downloading "pop-unders")

4

There are 4 answers

1
Stan James On BEST ANSWER

This problem was fixed by Microsoft. The .NET version is now returned as an HTTP request header, "X-ClickOnceSupport".

In PHP, you would get this via getenv()

print getenv('HTTP_X_CLICKONCESUPPORT');

In Perl

print $ENV{HTTP_X_CLICKONCESUPPORT};

In JavaScript it is not possible, according to this answer.

(This all started by examining the code of the Firefox .NET Assistant, which led me to search for the "X-ClickOnceSupport" header. Nothing like being able to view the source code to solve a mystery!)

1
AcesAndNates On

The way I got around this problem was to send back a response header telling the browser to function in compatibility then detecting the framework version with javascript on the navigator.userAgent.

Page Code-behind:

Response.Headers.Add("X-UA-Compatible", "IE=7");

Javascript on the page

// js to detect .net 3.5
// if it evaluates to true, then the user has .NET 3.5 installed
alert(navigator.userAgent.search(/\.NET.*?3\.5[\.\da-z]*?;/i) > -1);
2
Andy Johnson On

I don't see a way to do this. If the browser doesn't tell your server which frameworks are installed then you don't have any other way to find out.

3
wac On

navigator.userAgent gives you the extended UA string at least on IE9