【www.gdgbn.com--Silverlight】
在app.xaml.cs的application_startup中加入:
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。