1

I made a windows service application that I want to create a setup file. When User request application via our website url with query parameters, (Eg: http://test.com/setup.exe?id=1212) I need to change the current app.config key value to that query parameter value.

I also need to update this application automatically when new release is ready. So ClickOnce or squirrel for windows might be an option but as I couldn't find way to achieve above task.

Following questions are bit similar but don't solve this problem: * How can we retrieve query string information in a ClickOnce Application? * ClickOnce: How do I pass a querystring value to my app *through the installer*?

How can I achieve this?

Community
  • 1
  • 1
LittleOne
  • 131
  • 1
  • 4
  • 16
  • Which step is failing? Are you successfully receiving the query string in your application? – Zesty Aug 23 '16 at 10:38
  • Let me know if it works for you. – Zesty Aug 23 '16 at 10:52
  • Thanks @Zesty for the quick reply. My concern was when if I change the config file, it will cause for changing hash file so we might not be able to update it with clickonce. I'll check your answer and let you know the results. Thanks again. – LittleOne Aug 23 '16 at 11:04
  • Did it work? Is there anything wrong with the answer? – Zesty Aug 29 '16 at 12:25
  • @Zesty Sorry for late reply. It worked but there were some security concerns when installing on PCs. – LittleOne Mar 23 '17 at 16:25

1 Answers1

1

1. First, enable the query string parameters to be passed to the application.

enter image description here

2. Access the query string like this

private NameValueCollection GetQueryString()
{
    if (ApplicationDeployment.IsNetworkDeployed)
    {
        try
        {
            string rawQueryString = String.Empty;
            rawQueryString = ApplicationDeployment.CurrentDeployment.ActivationUri.Query;
            NameValueCollection queryString;
            try
            {
                queryString = HttpUtility.ParseQueryString(ApplicationDeployment.CurrentDeployment.ActivationUri.Query);
            }
            catch (Exception ex)
            {
                throw new Exception("Unauthorized access!");
            }
            return queryString;
        }
        catch (Exception ex)
        {
            if (ApplicationDeployment.CurrentDeployment == null)
            {
                throw new Exception("Deployment error");
            }
            else if (ApplicationDeployment.CurrentDeployment.ActivationUri == null)
            {
                throw new Exception("Unable to read data");
            }
            else
            {
                throw new Exception("Error with deployment: " + ex.Message);
            }
        }
    }
    else
    {
        throw new Exception("This application may not be accessed directly");
    }
}

3. Update the app.config

App.Config change value

Community
  • 1
  • 1
Zesty
  • 2,922
  • 9
  • 38
  • 69