在浏览器外访问 Silverlight 中的主机或 URL 信息
我正在构建一个 Silverlight 应用程序,该应用程序可以轻松部署到不同的网站,并且从应用程序内部,我需要访问托管 Silverlight 的域/主机。所以,我知道对于浏览器窗口内的应用程序,这段代码可以完美地工作:
HtmlPage.Document.DocumentUri.Host;
问题是,我也需要安装这个应用程序并在浏览器外模式下运行。但是,当我在 OOB 模式下调用相同的代码时,出现异常,这是完全正常的,因为 SL 未在浏览器中运行。但从逻辑上讲,SL 应用程序是从某个地方安装的,我需要访问该“原始”URL(或者至少,在这个项目中原始主机对我来说就足够了)。简而言之,如果应用程序是从 http://example.com/example.xap 安装的,如何才能我以编程方式访问字符串“http://example.com/example.xap”,同时用完浏览器?我不会提前知道这一点,因为该应用程序将是模块化的并部署到任何域。在独立存储中创建设置文件并设置域字符串(如果未设置)是唯一的选项,还是有更简单的方法?
谢谢,坎。
I'm building a Silverlight app which will be deployable to different websites easily, and from within the application, I need to access the domain/host that the Silverlight is hosted at. So, I know for apps within the browser window, this code would perfectly work:
HtmlPage.Document.DocumentUri.Host;
The problem is, I need this app to be installed and be run in out-of-browser mode too. However, when I call the same code in OOB mode, I get an exception, which is perfectly normal as SL in not running in a browser. But logically, the SL app has been installed from somewhere, and I need to access that "origin" URL (or at least, the original host is enough for me in this project). Simply put, if the app is installed from http://example.com/example.xap, how can I access the very string "http://example.com/example.xap" programatically while running out of browser? I won't be knowing this in advance as the app will be modular and be deployed to any domain. Is creating a settings file in isolated storage and setting the domain string if not set the only option, or is there a more trivial way?
Thanks, Can.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
Application.Current.Host.Source
获取地址(即使在 OOB 中)You can get the address (even in OOB) using
Application.Current.Host.Source
您可以从
WebClient
的新实例的BaseAddress
获取 Xap 的地址。BaseAddress
使用应用程序原始地址进行初始化,并将在 OOB 中工作。You can acquire the address of the Xap from the
BaseAddress
of a fresh instance of aWebClient
.The
BaseAddress
is initialised witth the application origin address and will work in an OOB.