Assigned AppPool resets after completion of Web Deployment Setup when using Custom Actions
-
Hi, I have an Web Application developed in .NET Framework 4.0 and created an deployment setup for the same. The client requirement is to create an custom Apppool and assign it to the virtual directory which is currently installing. To address this issue i created an custom actions project as described in following article. http://weblogs.asp.net/scottgu/archive/2007/06/15/tip-trick-creating-packaged-asp-net-setup-programs-with-vs-2005.aspx[^] I wrote the following code to create an apppool and assign it to the virtual directory.
private void CreateAppPoolIIS7()
{
using (ServerManager serverManager = new ServerManager())
{
string appPoolName = this.Context.Parameters["APPPOOL"];
ApplicationPool newPool;
newPool = serverManager.ApplicationPools.FirstOrDefault(x => x.Name == appPoolName);
if (newPool == null)
newPool = serverManager.ApplicationPools.Add(appPoolName);
newPool.ManagedRuntimeVersion = "v4.0";
newPool.ManagedPipelineMode = ManagedPipelineMode.Classic;
serverManager.CommitChanges();
}
}
private void AssignIIS7AppPoolToVirDir()
{
using (ServerManager serverManager = new ServerManager())
{
// Find Default Website
Microsoft.Web.Administration.Application newApp = null;
string appPoolName = this.Context.Parameters["APPPOOL"];
// Get the Root website
Site site = serverManager.Sites.First(s => s.Id == 1);
string installpath = this.Context.Parameters["INSTALLDIR"];
installpath = installpath.TrimEnd('\\');
//Get the name of the virtual directory
string virdirname = "/" + installpath.Substring(installpath.LastIndexOf('\\') + 1);newApp = site.Applications.FirstOrDefault(x => x.Path == virdirname); if (newApp != null) { newApp.ApplicationPoolName = appPoolName; serverManager.CommitChanges(); } else