一、如果在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
例如:
三、如果写一个程序来做不是更简单了。
下面是代码:
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 测井数据库系统程序访问授权控制
三、如果写一个程序来做不是更简单了。
下面是代码:
复制 保存
public override void Install(IDictionary stateSaver) { //MessageBox.Show( "OK" ); base.Install(stateSaver); StringDictionary parameters = Context.Parameters; string hostnamestr = parameters["hostname"]; if (hostnamestr == null || hostnamestr == "") { this.Rollback(null); } else { //MessageBox.Show( str.ToString() ); string[] fxs = this.UpToTheMinuteFX(); if (fxs != null && fxs.Length != 0) { foreach (string fxpath in fxs) { string fxpathtemp = fxpath + "\\caspol.exe"; if (File.Exists(fxpathtemp)) { //MessageBox.Show( fxpathtemp.ToString() ); this.startexe(fxpathtemp.Trim(), hostnamestr.Trim() + "/*"); } } } } } /// <summary> /// 添加代码组权限。 /// </summary> /// <param name="exepath">Caspol.exe程序的路径</param> /// <param name="url">代码组的url地址</param> private void startexe(string exepath, string url) { //声明一个程序信息类 System.Diagnostics.ProcessStartInfo Info = new System.Diagnostics.ProcessStartInfo(); //设置外部程序名 Info.FileName = exepath; //设置外部程序的启动参数(命令行参数)为test.txt Info.Arguments = "-quiet -machine -addgroup All_Code -url " + url + " FullTrust -n OGTLogDBMS -d 测井数据库系统程序访问授权控制"; //设置外部程序工作目录为 C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 //Info.WorkingDirectory = @"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727"; //声明一个程序类 System.Diagnostics.Process Proc; try { // //启动外部程序 // Proc = System.Diagnostics.Process.Start(Info); } catch (System.ComponentModel.Win32Exception ee) { MessageBox.Show("系统找不到指定的程序文件。", ee.ToString()); return; } //如果这个外部程序没有结束运行则对其强行终止 if (Proc.HasExited == false) { //Console.WriteLine("由主程序强行终止外部程序的运行!"); //Proc.Kill(); } else { //Console.WriteLine("由外部程序正常退出!"); } } /// <summary> /// 获取最各个版本的Framework目录。 /// </summary> /// <returns></returns> private string[] UpToTheMinuteFX() { //调用GetWindowsDirectory取得Windows路径 const int nchars = 128; StringBuilder Buff = new StringBuilder(nchars); GetWindowsDirectory(Buff, nchars); string fxstr = Buff.ToString(); fxstr = fxstr + @"\Microsoft.NET\Framework"; string[] fxstrs = Directory.GetDirectories(fxstr); if (fxstrs != null && fxstrs.Length != 0) return fxstrs; return null; }