- 1
- 0
- 约2.94千字
- 约 4页
- 2017-05-22 发布于重庆
- 举报
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
您可能关注的文档
最近下载
- 重庆市各地方周氏支族源流(1-170支族).doc VIP
- (高清版)B-T 6003.1-2022 试验筛 技术要求和检验 第1部分:金属丝编织网试验筛.pdf VIP
- (已压缩)TUCST007-2020房屋建筑与市政基础设施工程施工安全风险评估技术标准.docx VIP
- 2026年国家公务员考试申论真题及参考答案(考生回忆版).docx VIP
- 部编版语文二年级上册期中常考七大重点题型专项训练.docx VIP
- 机器人操作系统(ROS)及仿真应用 课件全套 第1--9章 Linux Ubuntu入门基础--- 基于ROS的服务机器人应用实例.ppt
- 压疮的预防及护理技术操作考核评分标准编辑.docx VIP
- 高温超导材料在量子计算中的应用前景.docx VIP
- 铺床术操作评分标准.doc VIP
- 2025年陕西高中学业水平合格性考试历史试卷真题(含答案) .pdf VIP
原创力文档

文档评论(0)