C#中操作IIS 7.0
2009-03-25 08:20:35 来源:WEB开发网这个是删除站点的方法,比较简单。
DeleteSite
/// <summary>
/// Delete an existent web site.
/// </summary>
/// <param name="siteName">Site name.</param>
public static void DeleteSite(string siteName)
{
using (ServerManager mgr = new ServerManager())
{
Site site = mgr.Sites[siteName];
if (site != null)
{
mgr.Sites.Remove(site);
mgr.CommitChanges();
}
}
}
然后是对虚拟目录的操作,包括创建和删除虚拟目录,都比较简单。
CreateVDir
public static void CreateVDir(string siteName, string vDirName, string physicalPath)
{
using (ServerManager mgr = new ServerManager())
{
Site site = mgr.Sites[siteName];
if (site == null)
{
throw new ApplicationException(String.Format("Web site {0} does not exist", siteName));
}
site.Applications.Add("/" + vDirName, physicalPath);
mgr.CommitChanges();
}
}
DeleteVDir
public static void DeleteVDir(string siteName, string vDirName)
{
using (ServerManager mgr = new ServerManager())
{
Site site = mgr.Sites[siteName];
if (site != null)
{
Microsoft.Web.Administration.Application app = site.Applications["/" + vDirName];
if (app != null)
{
site.Applications.Remove(app);
mgr.CommitChanges();
}
}
}
}
- ››IIS7 Request format is unrecognized.
- ››IIS Rewrite 配置
- ››IIS7错误:“由于扩展配置问题而无法提供您请求的...
- ››IIS7应用PHP Manager使用FastCGI快速部署
- ››IIS短文件和文件夹泄漏漏洞的分析
- ››IIS .net 网站打不开 http:404 出错
- ››IIS上asp.net网站无法访问(错误:服务器应用程序不...
- ››IIS+PHP配置图文详解
- ››IIS7 下日期显示格式的解决办法
- ››IIS6下部署ASP.NET MVC应用程序
- ››操作系统资源不足两种方案解决办法
- ››IIS 6 下配置以 FastCGI 跑 PHP
更多精彩
赞助商链接