C#操作IIS方法集合

2019-12-26 13:27:16王冬梅
  • object[] objectToArr = (object[])objectArr;  serverBindingStr = objectToArr[0].ToString(); 
  • }  else//只有一个绑定站点 
  • {  serverBindingStr = child.Properties["ServerBindings"].Value.ToString(); 
  • }  IISInfo iisInfo = new IISInfo(); 
  • iisInfo.DomainPort = serverBindingStr;  iisInfo.AppPool = child.Properties["AppPoolId"].Value.ToString();//应用程序池 
  • iisList.Add(iisInfo);  } 
  • }  } 
  • return iisList;  } 
  •    
  • public static bool CreateAppPool(string appPoolName, string Username, string Password)  { 
  • bool issucess = false;  try 
  • {  //创建一个新程序池 
  • DirectoryEntry newpool;  DirectoryEntry apppools = new DirectoryEntry("IIS://" + HostName + "/W3SVC/AppPools"); 
  • newpool = apppools.Children.Add(appPoolName, "IIsApplicationPool");   
  • //设置属性 访问用户名和密码 一般采取默认方式  newpool.Properties["WAMUserName"][0] = Username; 
  • newpool.Properties["WAMUserPass"][0] = Password;  newpool.Properties["AppPoolIdentityType"][0] = "3"; 
  • newpool.CommitChanges();  issucess = true; 
  • return issucess;  } 
  • catch // (Exception ex)   { 
  • return false;  } 
  • }   
  •   /// <summary> 
  • /// 建立程序池后关联相应应用程序及虚拟目录  /// </summary> 
  • public static void SetAppToPool(string appname,string poolName)  { 
  • //获取目录  DirectoryEntry getdir = new DirectoryEntry("IIS://localhost/W3SVC"); 
  • foreach (DirectoryEntry getentity in getdir.Children)  { 
  • if (getentity.SchemaClassName.Equals("IIsWebServer"))  { 
  • //设置应用程序程序池 先获得应用程序 在设定应用程序程序池  //第一次测试根目录