1

我做了一個Windows服務應用程序,我想創建一個安裝文件。當用戶通過我們的網站URL請求應用程序的查詢參數時,(例如:http://test.com/setup.exe?id=1212)我需要將當前的app.config鍵值更改爲該查詢參數值。使用查詢字符串參數從url下載自定義設置

我還需要在新版本準備就緒時自動更新此應用程序。所以ClickOnce或松鼠的窗戶可能是一個選擇,但因爲我無法找到方法來實現上述任務。

下面的問題是有點類似,但不解決這個問題: * 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*?

我怎樣才能做到這一點?

+0

哪一步失敗?你在應用程序中成功接收到查詢字符串了嗎? – Zesty

+0

讓我知道它是否適合你。 – Zesty

+0

感謝@Zesty的快速回復。我擔心的是,如果我更改配置文件,它將導致更改散列文件,因此我們可能無法使用clickonce更新它。我會檢查你的答案,並讓你知道結果。再次感謝。 – LittleOne

回答

1

1.首先,啓用查詢字符串參數傳遞給應用程序。

enter image description here

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 change value

相關問題