Some behaviors in many industries in China, it is necessary to restrict the use of Silverlight applications only under the specified domain name. For this purpose, the close-up example is for reference only.
This is the result of normal execution on the current page:
This is the result that the same program does not run under the specified domain name ():
Implementation Method:
1. Add accessdeniedpage. XAML and add a constructor.
public AccessDeniedPage(Uri uri) : this() { this.DataContext = uri; }
2. Set accessdeniedpage. XAML Foreground:
<Usercontrol X: class = "checkaccess. accessdeniedpage "xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation "xmlns: x =" http://schemas.microsoft.com/winfx/2006/xaml "xmlns: D =" http://schemas.microsoft.com/expression/blend/2008 "xmlns: MC =" http://schemas.openxmlformats.org/markup-compatibility/2006 "MC: ignorable =" D "D: designing Height = "300" D: designwidth = "400"> <grid background = "white" verticalalignment = "center" Height = "300"> <textblock text = "visit" horizontalalignment = "from the original page "center" verticalalignment = "TOP" fontsize = "29.333" margin =, 0, 0 "/>
2. Add the URI field to the app class and modify application_startup:
private void Application_Startup(object sender, StartupEventArgs e) { bool flag = false; try { flag = HtmlPage.Document.DocumentUri.Host.ToLower() == uri.Host.ToLower(); } catch { } if (flag) this.RootVisual = new MainPage(); else this.RootVisual = new AccessDeniedPage(uri); }
3. If your self-deployed xap and HTML are not in the same domain name, you need to set
<param name="enableHtmlAccess" value="true" />
Cause reference: http://msdn.microsoft.com/zh-cn/ff686925.aspx
Download slcheckaccess.zip