【问题标题】:Clickonce: applicationUri is null with Allow URL parameters to be passed set to trueClickonce:applicationUri 为空,允许传递 URL 参数设置为 true
【发布时间】:2019-09-16 06:07:43
【问题描述】:

我有一个通过 clickonce 部署的 winforms 应用程序,并希望收集查询字符串参数,以便发送带有参数的可点击链接。我曾尝试使用 ApplicationDeployment.CurrentDeployment.ActivationUri 和 AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData,但这些都不返回查询字符串。在 Visual Studio(或通过 MageUI 设置)中,“允许将 URL 参数传递给应用程序”设置为 true,并且此设置包含在部署清单中。

我是否缺少允许将查询字符串参数传递给应用程序的附加设置?

注意:我通过 Windows 资源管理器或 IE 调用已部署的应用程序,其 URI 为:file:C:\Users\\Deploy\TestApp.application?testarg123。这会导致问题吗?

谢谢

static void Main(){
...
Uri activationData = ApplicationDeployment.CurrentDeployment.ActivationUri;
                    MessageBox.Show(activationData.ToString());
...
}

【问题讨论】:

  • 只有通过http等网络部署才能使用,如果为真可以查看属性ApplicationDeployment.IsNetworkDeployed

标签: c# .net clickonce


【解决方案1】:

根据documentation on the ApplicationDeployment.ActivationUri Property,设置TrustUrlParameters = true并使用完整的URL(不是UNC路径)来启动程序应该允许访问查询字符串参数。

尝试将文件路径设为 URL,为您的查询参数设置一个值,然后使用 HttpUtility.ParseQueryString 访问该值。示例:

启动应用程序的 URL

file:///C:\Users\\Deploy\TestApp.application?testarg=123

获取查询字符串参数的方法

private NameValueCollection GetQueryStringParameters()
{
    NameValueCollection nameValueTable = new NameValueCollection();

    if (ApplicationDeployment.IsNetworkDeployed)
    {
        string queryString = ApplicationDeployment.CurrentDeployment.ActivationUri.Query;
        nameValueTable = HttpUtility.ParseQueryString(queryString);
    }

    return (nameValueTable);
}

【讨论】:

  • 感谢您的回复.. 我已经更新了我的代码以使用此方法检索查询字符串,但仍然没有数据... 如果我使用 `activationData = String.Join(" ,",GetQueryStringParameters( ).AllKeys); MessageBox.Show(activationData);`检索信息,返回数据为空
  • 打开程序的网址是什么?你也设置了TrustUrlParameters = true
  • 我正在使用 file:///C:\Users\..\Deploy\Test.application?testarg=123 启动。至于 TrustUrlParameters,我在 Visual Studio 中选中了相应的框(属性>发布>选项>允许将 URL 参数传递给应用程序)。已部署的 .application 清单也有行 ` `。还有其他地方需要设置吗?
猜你喜欢
  • 2014-06-10
  • 2019-07-19
  • 2012-01-09
  • 2021-07-30
  • 1970-01-01
  • 2020-04-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多