1.新建站點app
ServerManager iisManager = new ServerManager();ide
Site site = iisManager.Sites.Add("SiteName","http","*:80:"+siteUrl,sitePath);spa
iisManager.CommitChanges();ip
2.新建應用程序池ci
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();