C#操作IIS

1.新建站点

ServerManager iisManager = new ServerManager();

Site site = iisManager.Sites.Add("SiteName","http","*:80:"+siteUrl,sitePath);

iisManager.CommitChanges();

2.新建应用程序池

ServerManager iisManager = new ServerManager();

iisManager.ApplicationPools.Add(appoolname);
ApplicationPool newPool = iisManager.ApplicationPools[appoolname];
newPool.ManagedPipelineMode = ManagedPipelineMode.Integrated;
newPool.ManagedRuntimeVersion = "v2.0";
iisManager.CommitChanges();
3.站点绑定应用程序池
site.Applications["/"].ApplicationPoolName  = appoolName
4.添加域名
iisManager.Sites[SiteName].Bindings.Add("*:80:"+siteUrl,"http");
iisManager.CommitChanges();
5.删除站点和应用程序池
iisManager.Sites.Remove(site);
iisManager.ApplicationPools.Remove(newPool);
iisManager.CommitChanges();
6.停止一个站点
 ServerManager iisManager = new ServerManager();
 iisManager.Sites["NewSite"].Stop();
7.回收应用程序池(Recyciling an Application Pool)
 ServerManager iisManager = new ServerManager();
 iisManager.ApplicationPools["DefaultAppPool"].Recycle();

你可能感兴趣的:(IIS)