WinForm-C#操作IIS_DirectoryEntry

DirectoryEntry rootfolder = new DirectoryEntry("IIS://localhost/W3SVC/1/ROOT");  // IIS://服务器的名字/要操作的Web服务器类型/站点/站点的虚拟目录  

1、创建对象:

 

2、修改对象:

  #region 1、利用DirectoryEntry修改IIS默认站点的端口By网站端口
  DirectoryEntry ent = new DirectoryEntry("IIS://localhost/w3svc");  // 得到现默认站点的IP 端口 描述
  foreach (DirectoryEntry child in ent.Children)
  {
      if (child.SchemaClassName == "IIsWebServer" && child.Properties["ServerBindings"].Value != null && child.Properties["ServerBindings"].Value.ToString() == ":8090:")  // 后台系统默认为8090端口
      {
          string strServerBindings = child.Properties["ServerBindings"].Value.ToString();
          //解出端口Port
          char[] splitChar = { ':' };
          string[] strArr = strServerBindings.Split(splitChar);
          string newStrServerBindings = strArr[0] + $":{txtIISConfig_FrontBackPort.Text}:" + strArr[2];

          child.Properties["ServerBindings"].Value = newStrServerBindings;  // 重新给端口赋值
          child.CommitChanges();
      }
  }
  #endregion 利用DirectoryEntry修改IIS默认站点的端口By网站端口

3、删除对象:

 

参考:

    C# 创建虚拟目录

  C#使用DirectoryEntry操作IIS创建网站和虚拟路径

  .Net中如何操作IIS(原理篇)

 

posted @   ꧁执笔小白꧂  阅读(168)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
历史上的今天:
2021-04-14 Linux系统知识(二)-Root用户登录Ubuntu并且可以SSH
2021-04-14 Ubuntu20.04安装SqlServer2019教程-简洁版
点击右上角即可分享
微信分享提示