jackyrar 发表于 2015-8-14 08:06:19

IIS 5 和 IIS 6 的安全性差异

代码如下:


using System;
using System.DirectoryServices;

class TestIIS
{
    public static void Main()
    {            
      string comment,bindings;
      DirectoryEntry entry = new DirectoryEntry("IIS://LocalHost/w3svc");
      
         foreach(DirectoryEntry dir in entry.Children)
         {
               if(dir.SchemaClassName == "IIsWebServer")
               {
                   comment= dir.Properties["ServerComment"].Value.ToString();
                   bindings = dir.Properties["ServerBindings"].Value.ToString();         
                   if (bindings == ":80:")
                   {
                     Console.WriteLine(dir.Properties["MaxConnections"].Value);
                   }
               }
      }
       }
}
以上代码,在控制台下面是可以直接运行的.
如果将上面的代码稍稍修改(将Console.WriteLine改为Response.Write),封装成方法,放到一个aspx页面里面,拿到IIS上运行的话,会发现比较有趣的现象:
在IIS6上正常运行,在IIS 5上却会抛出拒绝存取的安全性异常.
如果你想让上述代码在IIS 5 和 6 上面都运行正常的话,需要做以下操作:
1.首先通过.NET FX 1.1 的配置工具将你的程序集配置为FullTrust
可以参考下面的链接:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/entsecpoladmin.asp
2.将你的IIS的匿名账号配置到管理员组里面,或者修改web.config文件
也可以参考下面的链接:
http://support.microsoft.com/default.aspx?scid=kb;en-us;306158
虽然可以解决问题,但是我的疑惑是:
IIS 6 的安全性应该比IIS 5 更全面,为什么在 IIS 6 上却正常?
上述的代码都是访问,并非修改设置, IIS 5 的安全要求就这么苛刻?
页: [1]
查看完整版本: IIS 5 和 IIS 6 的安全性差异