Пример #1
0
 /// <summary>
 ///  创建虚拟目录
 /// </summary>
 /// <param name="name">目录名:("mywebsite/Data")</param>
 /// <param name="path">物理路径(@"C:\Inetpub\AdminScripts")</param>
 public static void CreateIISDirectories(string name, string path)
 {
     IISManager test = new IISManager();
     test.Connect();
     VirtualDirectory vd = new VirtualDirectory();
     vd.Path = path;
     vd.Name = name;
     test.Create(vd);
 }
Пример #2
0
        //得到一个虚拟目录
        public VirtualDirectory GetVirDir(string strVirdir)
        {
            VirtualDirectory tmp = null;

            if (_virdirs.Contains(strVirdir))
            {
                tmp = _virdirs.Find(strVirdir);
                ((VirtualDirectory)_virdirs[strVirdir]).flag = 2;
            }
            else
            {
                throw new Exception("This virtual directory is not exists");
            }
            return(tmp);
        }
Пример #3
0
 //更新东东
 private void UpdateDirInfo(DirectoryEntry de, VirtualDirectory vd)
 {
     de.Properties["AnonymousUserName"][0] = vd.AnonymousUserName;
     de.Properties["AnonymousUserPass"][0] = vd.AnonymousUserPass;
     de.Properties["AccessRead"][0]        = vd.AccessRead;
     de.Properties["AccessExecute"][0]     = vd.AccessExecute;
     de.Properties["AccessWrite"][0]       = vd.AccessWrite;
     de.Properties["AuthBasic"][0]         = vd.AuthBasic;
     de.Properties["AuthNTLM"][0]          = vd.AuthNTLM;
     de.Properties["ContentIndexed"][0]    = vd.ContentIndexed;
     de.Properties["EnableDefaultDoc"][0]  = vd.EnableDefaultDoc;
     de.Properties["EnableDirBrowsing"][0] = vd.EnableDirBrowsing;
     de.Properties["AccessSSL"][0]         = vd.AccessSSL;
     de.Properties["Accessscript"][0]      = vd.Accessscript;
     de.Properties["DefaultDoc"][0]        = vd.DefaultDoc;
     de.Properties["Path"][0] = vd.Path;
     de.CommitChanges();
 }
Пример #4
0
        //执行批量更新
        private void BatchUpdate(VirtualDirectories vds)
        {
            _batchflag = true;
            foreach (object item in vds.Values)
            {
                VirtualDirectory vd = (VirtualDirectory)item;
                switch (vd.flag)
                {
                case 0:
                    break;

                case 1:
                    Create(vd);
                    break;

                case 2:
                    Update(vd);
                    break;
                }
            }
            _batchflag = false;
        }
Пример #5
0
 //更新东东
 private void UpdateDirInfo(DirectoryEntry de, VirtualDirectory vd)
 {
     de.Properties["AnonymousUserName"][0] = vd.AnonymousUserName;
     de.Properties["AnonymousUserPass"][0] = vd.AnonymousUserPass;
     de.Properties["AccessRead"][0] = vd.AccessRead;
     de.Properties["AccessExecute"][0] = vd.AccessExecute;
     de.Properties["AccessWrite"][0] = vd.AccessWrite;
     de.Properties["AuthBasic"][0] = vd.AuthBasic;
     de.Properties["AuthNTLM"][0] = vd.AuthNTLM;
     de.Properties["ContentIndexed"][0] = vd.ContentIndexed;
     de.Properties["EnableDefaultDoc"][0] = vd.EnableDefaultDoc;
     de.Properties["EnableDirBrowsing"][0] = vd.EnableDirBrowsing;
     de.Properties["AccessSSL"][0] = vd.AccessSSL;
     de.Properties["Accessscript"][0] = vd.Accessscript;
     de.Properties["DefaultDoc"][0] = vd.DefaultDoc;
     de.Properties["Path"][0] = vd.Path;
     de.CommitChanges();
 }
Пример #6
0
 //获取虚拟目录集合
 private VirtualDirectories GetVirDirs(DirectoryEntries des)
 {
     VirtualDirectories tmpdirs = new VirtualDirectories();
     foreach (DirectoryEntry de in des)
     {
         if (de.SchemaClassName == "IIsWebVirtualDir")
         {
             VirtualDirectory vd = new VirtualDirectory();
             vd.Name = de.Name;
             vd.AccessRead = (bool)de.Properties["AccessRead"][0];
             vd.AccessExecute = (bool)de.Properties["AccessExecute"][0];
             vd.AccessWrite = (bool)de.Properties["AccessWrite"][0];
             vd.AnonymousUserName = (string)de.Properties["AnonymousUserName"][0];
             vd.AnonymousUserPass = (string)de.Properties["AnonymousUserName"][0];
             vd.AuthBasic = (bool)de.Properties["AuthBasic"][0];
             vd.AuthNTLM = (bool)de.Properties["AuthNTLM"][0];
             vd.ContentIndexed = (bool)de.Properties["ContentIndexed"][0];
             vd.EnableDefaultDoc = (bool)de.Properties["EnableDefaultDoc"][0];
             vd.EnableDirBrowsing = (bool)de.Properties["EnableDirBrowsing"][0];
             vd.AccessSSL = (bool)de.Properties["AccessSSL"][0];
             vd.Accessscript = (bool)de.Properties["Accessscript"][0];
             vd.Path = (string)de.Properties["Path"][0];
             vd.flag = 0;
             vd.DefaultDoc = (string)de.Properties["DefaultDoc"][0];
             tmpdirs.Add(vd.Name, vd);
         }
     }
     return tmpdirs;
 }
Пример #7
0
 //更新一个虚拟目录
 public void Update(VirtualDirectory dir)
 {
     //判断需要更改的虚拟目录是否存在
     if (_virdirs.Contains(dir.Name))
     {
         DirectoryEntry ode = rootfolder.Children.Find(dir.Name, "IIsWebVirtualDir");
         UpdateDirInfo(ode, dir);
     }
     else
     {
         throw new Exception("This virtual directory is not exists.");
     }
 }
Пример #8
0
 //添加一个虚拟目录
 public void Create(VirtualDirectory newdir)
 {
     string strPath = "IIS://" + _server + "/W3SVC/" + _website + "/ROOT/" + newdir.Name;
     if (!_virdirs.Contains(newdir.Name) || _batchflag)
     {
         try
         {
             //加入到ROOT的Children集合中去
             DirectoryEntry newVirDir = rootfolder.Children.Add(newdir.Name, "IIsWebVirtualDir");
             newVirDir.Invoke("AppCreate", true);
             newVirDir.CommitChanges();
             rootfolder.CommitChanges();
             //然后更新数据
             UpdateDirInfo(newVirDir, newdir);
         }
         catch (Exception ee)
         {
             throw new Exception(ee.ToString());
         }
     }
     else
     {
         throw new Exception("This virtual directory is already exist.");
     }
 }