(转)防止silverlight application被别人引用
时间:2011-01-07 来源:allanli
if (!App.Current.Host.Settings.EnableHTMLAccess) throw new Exception("当前应用程序未允许与DOM通信"); string htmlUrl = System.Windows.Browser.HtmlPage.Document.DocumentUri.ToString(); if (!htmlUrl.Equals("http://foo.com/mypage.html")) throw new Exception("您无权使用该应用程序");
其中的http://foo.com/mypage.html就是你希望当前silverlight应用程序宿主的页面地址。这样结合防止frame就可以有效防止别人引用你的劳动成果啦。
最后看一下Settings中的属性,
public sealed class Settings { public Settings(); public bool EnableAutoZoom { get; set; } public bool EnableCacheVisualization { get; set; } public bool EnableFrameRateCounter { get; set; } public bool EnableGPUAcceleration { get; } public bool EnableHTMLAccess { get; } public bool EnableRedrawRegions { get; set; } public int MaxFrameRate { get; set; } public bool Windowless { get; } }
他们分别对应初始化silverlight(js控制)时的设置。如果我们要使用Host的相关属性、控制DOM、与js通信,那么EnableHTMLAccess 必须为True。
相关阅读 更多 +