Skip to main content
 首页 » 编程设计

c#之如何获取用于启动 XBAP 的 URL

2024年02月20日11findumars

如果有人从 http://myserver/folder/application.xbap 启动我的 xbap,我想获取 http://myserver/folder/ 部分来自应用程序中的 url。

我该怎么做?

我试过:

  • System.IO.Directory.GetCurrentDirectory()
  • System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName)
  • Environment.CurrentDirectory
  • System.Reflection.Assembly.GetExecutingAssembly().Location
  • AppDomain.CurrentDomain.BaseDirectory
  • System.Windows.Application.Current.StartupUri.AbsolutePath
  • System.Environment.GetCommandLineArgs()[0]
  • System.Deployment.Application.ApplicationDeployment.CurrentDeployment.DataDirectory

它们都返回 xbap 下载并运行的我机器上的本地位置,或者执行程序集的位置,例如 C:\Windows\SysWOW64

如何从应用程序本身访问用于启动 xbap 应用程序的 URL?

请您参考如下方法:

我相信是 BrowserInteropHelper.Source :

Gets the uniform resource identifier (URI) for the location from which a XAML browser application (XBAP) application was launched.