Download customized setup from url with the query string parameters

谁都会走 提交于 2020-01-30 09:33:09

问题


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?


回答1:


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

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



来源:https://stackoverflow.com/questions/39096708/download-customized-setup-from-url-with-the-query-string-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!