zoukankan      html  css  js  c++  java
  • Web页面嵌入复杂WinForm控件权限问题


    一、如果在web页面中嵌入复杂winform控件客户端在通过IE访问的时候,必须把该站点添加到受信任站点中而且还需要更改受信任站点区域安全性。这样既降低了系统的安全性,又对客户访问带来不便(第一访问之前都需要做如此复杂的操作),但是这样在做系统(CS/BS)时会节省大量的代码和工作量。为了解决这个弊端本人经过潜心研究,终于发现只要为站点创建代码组就可以了。具体操作如下:
     
    1、打开Microsoft .NET Framework 2.0 Configuration控制台程序(如果有多个fx版本只更改最新的即可)
    2、运行库安全策略
    3、计算机
    4、代码组
    5、右键All_code-新建-数据新建代码组名称-下一步--代码组权限类型选择“URL”--下面的URL中输入URL地址,例如:http://192.168.0.1/*
    6、使用现有权限集选择”FullTrust"---确定。
    7、重新启动计算机。

    二、这样操作也挺麻烦的,所以阿又经过对“%Systemroot%\Microsoft.NET\Framework”目录中文件的研究发现有一个命令可以来做这些活:CasPol.exe

    例如:caspol -quiet -machine -addgroup All_Code -url http://localhost/* FullTrust -n OGTLogDBMS -d 测井数据库系统程序访问授权控制

    三、如果写一个程序来做不是更简单了。
    下面是代码:

     1     public override void Install(IDictionary stateSaver)
     2         {
     3             //MessageBox.Show( "OK" );
     4
     5             base.Install( stateSaver );
     6            
     7             StringDictionary parameters = Context.Parameters;
     8             string hostnamestr = parameters["hostname"];
     9             if( hostnamestr == null || hostnamestr == "" )
    10             {               
    11                 this.Rollback(null);
    12             }
    13             else
    14             {
    15                 //MessageBox.Show( str.ToString() );
    16                 string[] fxs = this.UpToTheMinuteFX();
    17                 if( fxs != null && fxs.Length != 0 )
    18                 {
    19                     foreach( string fxpath in fxs )
    20                     {
    21                         string fxpathtemp = fxpath + "\\caspol.exe";
    22                         if( File.Exists( fxpathtemp ) )
    23                         {
    24                             //MessageBox.Show( fxpathtemp.ToString() );
    25                             this.startexe( fxpathtemp.Trim(),hostnamestr.Trim() + "/*" );
    26                         }
    27                     }
    28                 }
    29             }
    30         }
    31
    32         /// <summary>
    33         /// 添加代码组权限。
    34         /// </summary>
    35         /// <param name="exepath">Caspol.exe程序的路径</param>
    36         /// <param name="url">代码组的url地址</param>
    37         private void startexe( string exepath,string url )
    38         {
    39             //声明一个程序信息类
    40             System.Diagnostics.ProcessStartInfo  Info  =  new  System.Diagnostics.ProcessStartInfo();
    41
    42             //设置外部程序名
    43             Info.FileName  =  exepath;
    44
    45             //设置外部程序的启动参数(命令行参数)为test.txt
    46             Info.Arguments  =  "-quiet -machine -addgroup All_Code -url "+url+" FullTrust -n OGTLogDBMS -d 测井数据库系统程序访问授权控制";
    47            
    48             //设置外部程序工作目录为  C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
    49             //Info.WorkingDirectory  =  @"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727";
    50
    51             //声明一个程序类
    52             System.Diagnostics.Process  Proc;       
    53
    54             try
    55             {
    56                 //
    57                 //启动外部程序
    58                 //
    59                 Proc  =  System.Diagnostics.Process.Start(Info);
    60
    61             }
    62             catch(System.ComponentModel.Win32Exception  ee)
    63             {
    64                 MessageBox.Show("系统找不到指定的程序文件。",  ee.ToString());
    65                 return;
    66             }
    67
    68             //如果这个外部程序没有结束运行则对其强行终止
    69             if(Proc.HasExited  ==  false)
    70             {
    71                 //Console.WriteLine("由主程序强行终止外部程序的运行!");
    72                 //Proc.Kill();
    73             }
    74             else
    75             {
    76                 //Console.WriteLine("由外部程序正常退出!");
    77             }
    78         }
    79
    80         /// <summary>
    81         /// 获取最各个版本的Framework目录。
    82         /// </summary>
    83         /// <returns></returns>
    84         private string[] UpToTheMinuteFX()
    85         {
    86             //调用GetWindowsDirectory取得Windows路径
    87             const int nchars = 128;
    88             StringBuilder Buff = new StringBuilder(nchars);
    89             GetWindowsDirectory(Buff,nchars);
    90             string fxstr = Buff.ToString();
    91             fxstr = fxstr + @"\Microsoft.NET\Framework";
    92
    93             string[] fxstrs = Directory.GetDirectories( fxstr );
    94
    95             if( fxstrs != null && fxstrs.Length != 0 )
    96                 return fxstrs;           
    97             return null;
    98         }
    99     }
    四、由于写作水平和编程水平有限本文不妥之处请纠正。


    URL:http://www.cnblogs.com/mohai/archive/2006/09/06/362403.html

  • 相关阅读:
    毕业设计:专业填写格式
    关于《毕业设计指导记录》的建议
    毕业设计通知
    毕业设计答辩:幻灯片内容制作要点
    Latex 模版生成会议论文 不显示Keywords,而是显示 Index Terms- ,改成Keywords 方法
    mysql information_schema
    C# odbc
    cwRsync 配置文件详解
    Rsync
    openssl rsa 私钥 PKCS8私钥 公钥
  • 原文地址:https://www.cnblogs.com/yiki/p/722307.html
Copyright © 2011-2022 走看看