如何用C#删除IIS中的站点?在线等
//删除虚拟目录是这样的,但站点怎么做呢?
public static string DelVirtualDirectory(string WebSiteName,string nameDirectory)
{
try
{
string SiteID = GetSiteID(WebSiteName);
if (SiteID == null) return "error:该站点不存在.";
DirectoryEntry deRoot= new DirectoryEntry("IIS://localhost/W3SVC/" + SiteID + "/ROOT");
try
{
DirectoryEntry deVDir = new DirectoryEntry("IIS://localhost/W3SVC/" + SiteID + "/ROOT");
deRoot.RefreshCache();
deVDir = new DirectoryEntry("IIS://localhost/W3SVC/" + SiteID + "/ROOT");
deVDir.Invoke("AppDelete", null);
deRoot.Children.Remove(deVDir);
deRoot.CommitChanges();
deRoot.Close();
return "successful:删除虚拟目录" + nameDirectory + "成功!";
}
catch
{
return "error:该虚拟目录不存在.";
}
}
catch(Exception e)
{
return "error:删除目录失败." + e.Message;
}
}
//查找对应的虚拟站点.
public static string GetSiteID(string WebSiteName)
{
DirectoryEntry root = new DirectoryEntry("IIS://localhost/W3SVC");
try
{
string SiteID= null;
string hostname;
foreach(DirectoryEntry bb in root.Children)
{
try
{
//if(Convert.ToInt32(bb.Name.Trim()) < 0) continue;
PropertyValueCollection pvc = bb.Properties["ServerBindings"];
String[] srvBindings = ((string)pvc[0]).Split(new char[] {':'});
hostname = srvBindings[2].Trim();
//判断,可换用hostname
//if (WebSiteName == bb.Properties["ServerComment"].Value.ToString()) SiteID=bb.Name;
if (WebSiteName == hostname) SiteID=bb.Name;
// Clear Variable
hostname = "";
}
catch{}
}
if (SiteID == null) return null;
return SiteID;
}
catch
{
return null;
}
}
这里是删除虚拟目录的方法,那删除站点怎么做?
public static string DelVirtualDirectory(string WebSiteName,string nameDirectory)
{
try
{
string SiteID = GetSiteID(WebSiteName);
if (SiteID == null) return "error:该站点不存在.";
DirectoryEntry deRoot= new DirectoryEntry("IIS://localhost/W3SVC/" + SiteID + "/ROOT");
try
{
DirectoryEntry deVDir = new DirectoryEntry("IIS://localhost/W3SVC/" + SiteID + "/ROOT");
deRoot.RefreshCache();
deVDir = new DirectoryEntry("IIS://localhost/W3SVC/" + SiteID + "/ROOT");
deVDir.Invoke("AppDelete", null);
deRoot.Children.Remove(deVDir);
deRoot.CommitChanges();
deRoot.Close();
return "successful:删除虚拟目录" + nameDirectory + "成功!";
}
catch
{
return "error:该虚拟目录不存在.";
}
}
catch(Exception e)
{
return "error:删除目录失败." + e.Message;
}
}
//查找对应的虚拟站点.
public static string GetSiteID(string WebSiteName)
{
DirectoryEntry root = new DirectoryEntry("IIS://localhost/W3SVC");
try
{
string SiteID= null;
string hostname;
foreach(DirectoryEntry bb in root.Children)
{
try
{
//if(Convert.ToInt32(bb.Name.Trim()) < 0) continue;
PropertyValueCollection pvc = bb.Properties["ServerBindings"];
String[] srvBindings = ((string)pvc[0]).Split(new char[] {':'});
hostname = srvBindings[2].Trim();
//判断,可换用hostname
//if (WebSiteName == bb.Properties["ServerComment"].Value.ToString()) SiteID=bb.Name;
if (WebSiteName == hostname) SiteID=bb.Name;
// Clear Variable
hostname = "";
}
catch{}
}
if (SiteID == null) return null;
return SiteID;
}
catch
{
return null;
}
}
这里是删除虚拟目录的方法,那删除站点怎么做?
...全文
相关推荐
IIS多站点_C#_iis_多站点源码_
本系统源码专注于C#语言实现对IIS多站点的管理,包括创建、停止、删除站点以及重启IIS服务。**1. C#语言基础**C#是一种面向对象的编程语言,由微软开发,主要用于.NET框架。
C#创建IIS站点,C#在2003系统创建站点
本篇文章将深入探讨如何使用C#编程语言在Windows Server 2003上创建IIS站点。首先,我们要了解的是C#如何与IIS进行交互。
用C#在IIS中创建一个Web站点源代码
通过`ServerManager`类,我们可以读取、创建、修改和删除IIS的配置信息。以下是一个基本的步骤来创建一个Web站点:1.
C#操作IIS程序池及站点的创建配置实现代码
本篇文章将深入探讨如何使用C#代码来创建、配置IIS程序池以及站点,特别是针对IIS7及其以上的版本。
C#实现获取IIS站点及虚拟目录信息的方法
"C#编程语言可以用来获取IIS(Internet Information Services)服务器上的站点和虚拟目录信息。通过使用System.DirectoryServices命名空间中的Dire


