tags:

views:

177

answers:

1

How can I parse the query string (GET / POST parameters) sent to an application's manifest in .NET ?
From one application, I am calling MyApp.application which needs to install my .NET application (if not installed) and in any case it should call the application which should parse the GET parameters.

Later edit:
I have a .NET application which should be installed via ClickOnce. It's already published on a web server. The execution of the application is done by calling the MyApp.application file from an external application (written in PHP). This normally checks for updates and installs the application if required, then it calls the application so this is the file that will always be called from the external app.
The external app sends parameters via a GET query to this file which should be processed in the .NET app (the parameters include credentials information because this the easiest way I can see to implement automatic login).
If the GET parameters are sent to MyApp.application, how can I process them in MyApp.cs every time it's launched?

+2  A: 

First, you need to ensure that query string options are enabled (project properties=>publish=>options=>manifests=>allow url parameters...);

Then - to allow parity between standalone and web, I use something like below (the important bit is ActivationArguments.ActivationData; you'll need a reference to System.Deployment.dll too).

You could also look at System.Deployment.Application.ApplicationDeployment.CurrentDeployment.ActivationUri, which MSDN has a good example for here.


    public static string[] GetStartupArguments() {
        List<string> allOptions = new List<string>();
        try // command line
        {
            string[] options = System.Environment.GetCommandLineArgs();
            if (options != null) { // strip the first (the exe name)
                int length = options.Length;
                for (int i = 1; i < length; i++)
                    allOptions.Add(options[i]);
            }
        } catch { } // lazy swallow
        try // query string
        {
            if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed) {
                string[] options = AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData;
                if (options != null && options.Length > 0) {
                    foreach (string queryItem in new Uri(options[0]).Query.TrimStart('?').Split('&')) {
                        allOptions.Add(System.Web.HttpUtility.UrlDecode(queryItem));
                    }
                }
            }
        } catch { } // lazy swallow

        return allOptions.ToArray();
    }
Marc Gravell