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

  • 相关阅读:
    C#获取中英文混合字符串长度和截取函数
    页面和块高度在JavaScript中的属性总结
    跨浏览器兼容添加到收藏夹/书签的Javascript
    转:28个免费的在线文件格式转换工具
    2009年十大经典网络小说
    某企业网站建设步骤
    转:Web安全工具大汇聚
    枚举
    VS中不显示解决方案的解决方法
    SQL 分页存储过程
  • 原文地址:https://www.cnblogs.com/Aimeast/p/2012269.html
Copyright © 2011-2022 走看看