如何知道我的 Silverlight 应用程序是否在本地运行?
我正在开发 Silverlight 4 应用程序,我想在本地部署应用程序以进行测试时启用/禁用某些功能。
例如,当我在本地测试应用程序时,将禁用指标收集,以避免向我的“实时”指标数据库发送垃圾邮件。
我目前执行此操作的方法是检查主机名。例如,在我的 App.xaml.cs 文件中:
if (HtmlPage.Document.DocumentUri.Host == "localhost")
{
// Do stuff only when deployed locally
}
是否有更好的方法来执行此操作?
I am developing a Silverlight 4 application and I want to enable/disable some features when deploying the app locally for testing purposes.
For example, metrics collecting will be disabled when I test the application locally to avoid spamming my database of "live" metrics.
The way that I am currently doing this is by checking the host name. For example, in my App.xaml.cs file:
if (HtmlPage.Document.DocumentUri.Host == "localhost")
{
// Do stuff only when deployed locally
}
Is there a better way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我创建了两个 html 页面来测试我的代码,例如 mysilverlightpage.html 和 myslpage.notracking.html。然后在 myslpage.notracking.html 的对象嵌入标记中添加一个 initparam:
然后在我的代码中,我检查我的 InitParams 参数:
现在可以检查发布版本的功能而不会使跟踪指标无效。
I create two html pages to test my code, for example mysilverlightpage.html and myslpage.notracking.html. Then in the object embed tag for myslpage.notracking.html I add an initparam:
Then in my code, I do a check on my InitParams params:
Now it's possible to check the release version for functionality without invalidating your tracking metrics.
另一种解决方案是在 Silverlight 项目的“生成”选项卡中定义您自己的条件编译符号(例如:LOCAL),然后使用 #if 语句。当您准备好移动应用程序时,请取出该符号。 (或者以相反的方式进行,因为您实际上正在禁用代码)
Another solution would be to define your own Conditional Compilation symbol in the Build tab of your Silverlight project (eg: LOCAL) and then using the #if statement. Take out the symbol when you're ready to move your app. (Or do it the opposite way since you're actually disabling code)