代码是网上,一搜一大堆那种,就不全贴了
形如
private DirectoryEntry doCreateWebSite(DirectoryEntry root, int SiteId)
{
try
{
return (DirectoryEntry)root.Invoke("Create", "IIsWebServer", SiteId); //siteID
}
catch (System.Reflection.TargetInvocationException)
{
return null;
}
} string rootPath = string.Format("IIS://{0}", Environment.MachineName);
DirectoryEntry root = new DirectoryEntry(rootPath + "/W3SVC");
int siteID = 1 ;
foreach (DirectoryEntry e in root.Children)
{
if (string.Compare(e.SchemaClassName , "IIsWebServer", true)==0)
{
int ID = Convert.ToInt32(e.Name);
if (ID >= siteID)
siteID = ID + 1;
}
}
bool IISUnderNT; DirectoryEntry IISSchema = new System.DirectoryServices.DirectoryEntry(rootPath + "/Schema/AppIsolated");
if (IISSchema.Properties["Syntax"].Value.ToString().ToUpper() == "BOOLEAN")
IISUnderNT = true;
else
IISUnderNT = false;
IISSchema.Dispose();
DirectoryEntry site = null; site = doCreateWebSite(root, ++siteID);
...在2003下即IIS6下创建站点是正确的,Vista IIS7下也是正确的,就是多了一堆无效的空站点,不知道什么原因看图
形如
private DirectoryEntry doCreateWebSite(DirectoryEntry root, int SiteId)
{
try
{
return (DirectoryEntry)root.Invoke("Create", "IIsWebServer", SiteId); //siteID
}
catch (System.Reflection.TargetInvocationException)
{
return null;
}
} string rootPath = string.Format("IIS://{0}", Environment.MachineName);
DirectoryEntry root = new DirectoryEntry(rootPath + "/W3SVC");
int siteID = 1 ;
foreach (DirectoryEntry e in root.Children)
{
if (string.Compare(e.SchemaClassName , "IIsWebServer", true)==0)
{
int ID = Convert.ToInt32(e.Name);
if (ID >= siteID)
siteID = ID + 1;
}
}
bool IISUnderNT; DirectoryEntry IISSchema = new System.DirectoryServices.DirectoryEntry(rootPath + "/Schema/AppIsolated");
if (IISSchema.Properties["Syntax"].Value.ToString().ToUpper() == "BOOLEAN")
IISUnderNT = true;
else
IISUnderNT = false;
IISSchema.Dispose();
DirectoryEntry site = null; site = doCreateWebSite(root, ++siteID);
...在2003下即IIS6下创建站点是正确的,Vista IIS7下也是正确的,就是多了一堆无效的空站点,不知道什么原因看图
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货