使用.NET的目录服务就可以访问IIS的设置,添加虚拟目录其实就是创建一个DirectoryEntry
复杂的在于DirectoryEntry的属性,其实就是虚拟目的一些配置,比如,权限,是否要log,应用程序名等
Properties非常多,而且文档不太好找
详细可以参考MSDN以下内容
help://MS.MSDNQTR.2004JUL.1033/iissdk/iis/configuring_properties_in_the_iis_user_interface.htm
代码示例:
const String constIISWebSiteRoot = "IIS://localhost/W3SVC/1/ROOT";
DirectoryEntry root = new DirectoryEntry(constIISWebSiteRoot);
DirectoryEntry entry = new DirectoryEntry(constIISWebSiteRoot + "/" + virtualDirName);
DirectoryEntry tbEntry = root.Children.Add(virtualDirName, "IIsWebVirtualDir");
//must be end with a '/'
tbEntry.Properties["Path"][0] = virtualDirPath;
tbEntry.Invoke("AppCreate",true);
tbEntry.Properties["AccessRead"][0] = true;
tbEntry.Properties["ContentIndexed"][0] = false;
tbEntry.Properties["DefaultDoc"][0] = "index.asp";
tbEntry.Properties["AppFriendlyName"][0] = virtualDirName;
tbEntry.Properties["AppIsolated"][0] = 2;
tbEntry.Properties["AccessScript"][0] = true; <