[Silverlight] limits that Silverlight applications can only be used under a specified domain name to protect your SL Program

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.