asp.net - Stop App Pools from Application's Physical Path - ServerManager C# -
using servermanager class possible app pool name physical path application? have been testing following code:
using (var manager = new servermanager()) //using (var manager = servermanager.openremote("xxx")) //uncomment line enable remote debugging, comment out line 1821, update server name value { //get site using website id var site = manager.sites.singleordefault(m => m.id == websiteid); if (site != null) { //foreach (application app in site.applications) //{ bld.appendline("1. stopping app pool for: " + site.name); //get application pool name var application = site.applications.singleordefault(m => m.virtualdirectories["/"].physicalpath == @"d:/inetpub/testsite1"); //returns null //get application binded sitename var application1 = site.applications.singleordefault(m => m.path == "/testsite1"); //return info require var apppoolname = application.applicationpoolname; //var apppoolname = site.applications.firstordefault().applicationpoolname; var apppool = manager.applicationpools[apppoolname]; if (apppool != null) { //check app pool state if (apppool.state == objectstate.stopped) { //app pool stopped bld.appendline("1. app pool: " + apppool.name + " stopped."); } else { //stop app pool apppool.stop(); bld.appendline("1. app pool: " + apppool.name + " stopped."); } } else { bld.appendline("1. no app pool found."); failflag = true; } //} } else { bld.appendline("1. siteid: " + websiteid + " not exist."); failflag = true; } }
}
i use physical path application rather virtual path there hundreds of applications in applications db , can't 100% have been configured in iis 2 paths in sync e.g d:\inetpub\testsite1 , /testsite1
changing fwd slashes slashes on line of code seems have did trick me:
var application = site.applications.singleordefault(m => m.virtualdirectories["/"].physicalpath == @"d:\inetpub\testsite1");
in code using parameter instead of hardcoding physical path have this:
using (var manager = new servermanager()) { //get site using website id var site = manager.sites.singleordefault(m => m.id == websiteid); if (site != null) { bld.appendline("1. stopping app pool for: " + site.name + " " + targetpath); var application = site.applications.singleordefault(m => m.virtualdirectories["/"].physicalpath == @targetpath); var apppoolname = application.applicationpoolname; var apppool = manager.applicationpools[apppoolname]; if (apppool != null) { ...
hope helps else in future.
Comments
Post a Comment