zoukankan      html  css  js  c++  java
  • 【Silverlight】限制Silverlight应用只能在指定的域名下使用,保护你的SL程序

    介于国许多行业的某些行为,有必要限制Silverlight应用只能在指定的域名下使用。为了达到这一目的,特写一样例,仅供参考。

    这是在当前页面正常执行的结果:

    这是同一个程序不在指定域名下运行的结果(截图):

    实现方法:

    1、添加AccessDeniedPage.xaml,增加一个构造函数

            public AccessDeniedPage(Uri uri)
                : this()
            {
                this.DataContext = uri;
            }

    2、设置AccessDeniedPage.xaml前台:

    <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:DesignHeight="300" d:DesignWidth="400">
        
        <Grid>
        
    		<Grid Background="White" VerticalAlignment="Center" Height="300">
    			<TextBlock Text="请从原始页面访问" HorizontalAlignment="Center" VerticalAlignment="Top" FontSize="29.333" Margin="0,75,0,0"/>
    			<HyperlinkButton Content="{Binding}" Margin="0,0,0,100" HorizontalAlignment="Center" VerticalAlignment="Bottom" NavigateUri="{Binding}" FontSize="21.333"/>
    		</Grid>
    	</Grid>
    </UserControl>
    

    2、给App类加上uri字段,把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、如果你自己部署的xap和html不在同一个域名下,还需要设置

    <param name="enableHtmlAccess" value="true" />
    原因参考:http://msdn.microsoft.com/zh-cn/ff686925.aspx

    下载 SLCheckAccess.zip

  • 相关阅读:
    前端性能优化总结
    Vue style 深度作用选择器 >>> 与 /deep/(sass/less)
    NPM依赖包版本号~和^的区别及最佳实践
    umi部分使用总结
    FIS 插件机制
    从0到1发布一个npm包
    页面性能监控之performance
    1和new Number(1)有什么区别
    实现一个hoverDelay延迟hover
    触发浏览器回流的属性方法一览表
  • 原文地址:https://www.cnblogs.com/Aimeast/p/2012269.html
Copyright © 2011-2022 走看看