问题描述
我做了,我想创建一个安装文件,Windows服务应用程序。通过我们的网站的网址当用户请求的应用程序与查询参数(例如:)我需要改变当前的app.config键值的查询参数值。
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.
我还需要在新版本已经准备好自动更新这个应用程序。所以的ClickOnce和松鼠的Windows可能是一种选择,而是因为我找不到方法来实现上述任务。
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 retreive 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。首先,使查询字符串参数被传递给应用程序。
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
这篇关于从URL下载用户定制的设置与查询字符串参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!