.net – Passing URL parameters to a ClickOnce application in any browser

clickoncedeploymentneturl

I have a ClickOnce application, and I need the ability to pass URL parameters to it. For example, a user could click a URL of the form "http://foo.bar/MyApp.application?flavor=grape", and this will launch my application, passing the "?flavor=grape" query to it.

Unfortunately, it looks like this only works in IE out of the box. On Firefox and Chrome, the user must install add-ons in order to get ClickOnce deployment to work. My users work in a restrictive corporate environment, and are not allowed to install any add-ons, or anything else for that matter (ClickOnce does work for them, though). So, what do I do ?

One hack I could think of is registering my application as a file handler for some sufficiently unique file extension, such as ".bugmaster" . Then — or so my theory went — I could have my webserver generate a file named "flavor_grape.bugmaster"; the user will click a URL pointing to that file, then choose "Run" instead of "Save", and this will launch my application, who will then parse the filename for URL parameters. Unfortunately, this approach doesn't work either. It works perfectly fine when the "flavor_grape.bugmaster" file is opened from the local filesystem, but, for some reason, this does not work when the user attempts to open the file from a browser.

Does anyone have any other ideas ?

Best Answer

There's a nifty little trick to ClickOnce in that you can actually encode parameters directly into the URL that gets used by setup.exe. So for example, to create a setup.exe that contains your 'flavor=grape' parameter, you could run the following from the command line:

copy setup.exe setup-for-grape.exe
setup.exe -url="http://foo.bar/MyApp.application?flavor=grape" /dest=setup-for-grape.exe

This uses the undocumented /dest flag to output the results to the setup-for-grape.exe file, instead of modifying the original setup.exe. After doing this, setup-for-grape.exe will point to your URL and will contain your flavor=grape parameter. Note that if you are using signing, you'll need to do this to an un-signed copy of your setup.exe, and then sign it afterwards, as it breaks the signature.

If the number of possible parameter choices is fairly limited, you can just generate setup.exe's for them all and link to them from your website.

On the other hand, if there are an unlimited number of choices, you can set up a web service which takes in some parameters, generates a setup.exe with desired parameters encoded in it, and spits it back out to the client. I have used this method to generate setup.exe's for clients connected to specific servers - the client installation URLs have the server connection info encoded in them, so when a client is installed it automatically knows what server to connect to.

Of course, if you don't want to use setup.exe, or if your restrictive corporate environment disallows it, all of this goes straight out the window. But hopefully you'll find it useful, or at least informative.