如何得到我打开的应用程序的URL
本文关键字:应用程序 URL 何得 | 更新日期: 2023-09-27 18:15:21
另一个asp.net/c#应用程序通过带有查询字符串的链接打开我的WPF应用程序。当我的WPF应用程序在浏览器中打开或启动时,我如何捕获或获取URL?
https://msdn.microsoft.com/en-us/library/ms172242.aspx
private NameValueCollection GetQueryStringParameters()
{
NameValueCollection nameValueTable = new NameValueCollection();
if (ApplicationDeployment.IsNetworkDeployed)
{
string queryString = ApplicationDeployment.CurrentDeployment.ActivationUri.Query;
nameValueTable = HttpUtility.ParseQueryString(queryString);
}
return (nameValueTable);
}
根据Jonathan Allen的建议,我的工作代码下面避免使用系统。httptility的Web参考
private NameValueCollection GetQueryStringParameters()
{
NameValueCollection nameValueTable = new NameValueCollection();
if (ApplicationDeployment.IsNetworkDeployed)
{
string queryString = ApplicationDeployment.CurrentDeployment.ActivationUri.Query;
string[] querySegments = queryString.Split('&');
foreach (string segment in querySegments)
{
string[] parts = segment.Split('=');
if (parts.Length > 0)
{
string key = parts[0].Trim(new char[] { '?', ' ' });
string val = parts[1].Trim();
//MessageBox.Show("key=" + key + " val=" + val);
nameValueTable.Add(key, val);
}
}
}
return (nameValueTable);
}