一、通過URL參數給WPF瀏覽器應用程序傳參數
比如在瀏覽器地址欄輸入http://192.168.4.158/MyWPFWeb/MyWPFWeb.xbap?userid=administrator&password=voicecyber
WPFWeb程序中獲取參數的方法如下:
try
{
if (ApplicationDeployment.IsNetworkDeployed)
{
NameValueCollection NVCollection = new NameValueCollection();
NVCollection = HttpUtility.ParseQueryString(ApplicationDeployment.CurrentDeployment.ActivationUri.Query);
QueryString = NVCollection.ToString();
MessageBox.Show(QueryString);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
return;
}
注意:1、需要引入System.Deployment.Application、System.Web名字空間。
2、發佈程序時 項目——屬性——發佈——選項——清單 要勾上“允許嚮應用程序傳遞URL參數”