使用查询字符串参数从url下载自定义设置

我制作了一个Windows服务应用程序,我想创建一个安装文件。 当用户通过我们的网站URL请求应用程序请求查询参数时,(例如: http : //test.com/setup.exe? id = 1212 )我需要将当前的app.config键值更改为该查询参数值。

我还需要在新版本准备就绪时自动更新此应用程序。 因此,ClickOnce或squirrel for windows可能是一种选择,但我无法找到实现上述任务的方法。

以下问题有点类似但不解决此问题:* 如何在ClickOnce应用程序中检索查询字符串信息? * ClickOnce:如何通过安装程序*将查询字符串值传递给我的应用*?

我怎样才能做到这一点?

1.首先,启用查询字符串参数以传递给应用程序。

在此处输入图像描述

2.像这样访问查询字符串

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.更新app.config

App.Config更改值

Interesting Posts