c创建web虚拟目录和FTP虚拟目录的代码.docVIP

  • 1
  • 0
  • 约2.94千字
  • 约 4页
  • 2017-05-22 发布于重庆
  • 举报

c创建web虚拟目录和FTP虚拟目录的代码.doc

c创建web虚拟目录和FTP虚拟目录的代码

using System; using System.DirectoryServices; namespace VirtualDirectory { /// summary /// Summary description for IISManager. /// /summary public class IISManager { /// summary /// Constructor /// /summary /// param name=serverNameName of the IIS Server/param public IISManager(string serverName) { _serverName = serverName; } /// summary /// Default constructor uses localhost as default server /// /summary public IISManager() { _serverName = localhost; } /// summary /// Connect to IISServer /// /summary public void Connect() { try { _iisServer = new DirectoryEntry(IIS:// + _serverName + /W3SVC/1); } catch (Exception e) { throw new Exception(Could not connect to: + _serverName,e); } } /// summary /// Create a virtual directory /// /summary /// param name=nameDirectoryName of the new virtual directory/param /// param name=realPathPath of the directory/param public void CreateVirtualDirectory(string nameDirectory,string realPath) { DirectoryEntry folderRoot = _iisServer.Children.Find(Root,VirDirSchemaName); try { DirectoryEntry newVirDir = folderRoot.Children.Add(nameDirectory,VirDirSchemaName); // Set Properties newVirDir.Properties[AccessRead].Add(true); newVirDir.Properties[Path].Add(realPath); // Create a Application newVirDir.Invoke(AppCreate,true); // Save Changes newVirDir.CommitChanges(); folderRoot.CommitChanges(); _iisServer.CommitChanges(); } catch (Exception e) { throw new Exception(Virtual Directory + nameDirectory + Already Exists,e); } } #region Properties public string ServerName { get { return _serverName; } set { _serverName = value; } } #endregion public static string VirDirSchemaName = IIsWebVirtualDir; #region Private Members private string _serverName; private DirectoryEntry _iisServer; #endregion } } 然后如此调用: // T

文档评论(0)

1亿VIP精品文档

相关文档