I'm trying to create an application pool before install and set that application pool for the installed application post install in a visual studio web setup project
Trying to filter out the applications under a site so that the newly created application pool applies only to a specific application with the name "websetup9090" in this case. Tried a few methods to compare the name of the applications but none of them worked
or
If there is any way to run the custom action to create the application pool before it reaches the Installation address UI page it would be even better as there is an option to select the application pool for the user via dropdown
The code below is called via custom action in the web setup project
protected override void OnBeforeInstall(IDictionary stateSaver)
{
ServerManager iisManager = new ServerManager();
bool chkPool = false;
chkPool = iisManager.ApplicationPools.Any(t => t.Name == "Pool99");
if (chkPool == false)
{
var myPool = iisManager.ApplicationPools.Add("Pool99");
myPool.ManagedPipelineMode = ManagedPipelineMode.Integrated;
myPool.ManagedRuntimeVersion = ".NET CLR version 4.0.30319";
myPool.Enable32BitAppOnWin64 = true;
iisManager.CommitChanges();
}
}
protected override void OnAfterInstall(IDictionary stateSaver)
{
ServerManager iisManager = new ServerManager();
var sites = iisManager.Sites;
foreach (Site site in sites)
{
if (site.Name == "Default Web Site")
{
Site mySite = site;
mySite.Stop();
var myPools = iisManager.ApplicationPools;
foreach (ApplicationPool pool in myPools)
{
if (pool.Name == "Pool99")
{
ApplicationPool myPool = pool;
foreach (var item in mySite.Applications)
{
if (item.Path.ToLower().IndexOf("websetup9090") > 0)
{
item.ApplicationPoolName = myPool.Name;
}
}
iisManager.CommitChanges();
myPool.Recycle();
}
}
iisManager.CommitChanges();
mySite.Start();
}
}
}