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#使用DirectoryEntry操作IIS创建网站和虚拟路径
本文来自博客园,作者:꧁执笔小白꧂,转载请注明原文链接:https://www.cnblogs.com/qq2806933146xiaobai/p/17317302.html