我正在尝试使用c#创建应用程序池并将其分配给IIS6和IIS7中的网站。我设法为IIS7 using Microsoft.Web.Administration;
执行此操作,但由于IIS6不支持,我想使用System.DirectoryServices;
完成此操作。我已设法创建应用程序池,但分配应用程序池不起作用。
这是我到目前为止所拥有的......
private static string DefaultAppPool = "DefaultAppPool";
public static void SetApplicationPoolIIS6(string websiteName)
{
string metabasePath = "IIS://localhost/W3SVC";
string appPoolName = GetSavedApplicationPoolName(websiteName);
if (string.IsNullOrEmpty(appPoolName) || appPoolName.Equals(DefaultAppPool))
appPoolName = websiteName + "AppPool";
bool isAppPoolCreated = IsAppPoolCreatedIIS6(websiteName, appPoolName);
if (!isAppPoolCreated)
CreateApplicationPoolIIS6(appPoolName, metabasePath);
DirectoryEntry w3svc = new DirectoryEntry(metabasePath);
w3svc.RefreshCache();
foreach (DirectoryEntry item in w3svc.Children)
{
string siteName = item.Properties["ServerComment"].Value == null ? "" : item.Properties["ServerComment"].Value.ToString();
if (string.IsNullOrEmpty(siteName))
continue;
if (siteName.Equals(websiteName))
{
item.Invoke("Stop", null);
item.Properties["AppPoolId"].Value = appPoolName;
item.CommitChanges();
item.Invoke("Start", null);
break;
}
}
w3svc.CommitChanges();
DirectoryEntry w3svc2 = new DirectoryEntry(metabasePath);
w3svc2.RefreshCache();
SaveWebSiteSettingsIIS6(websiteName, appPoolName);
}
任何想法为什么以下行不分配创建的应用程序池?
item.Properties["AppPoolId"].Value = appPoolName;
item.CommitChanges();
非常感谢任何帮助。谢谢。