المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Assigned AppPool resets after completion of Web Deployment Setup when using Custom Actions



C# Programming
11-15-2011, 07:00 PM
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[^ (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 { MessageBox.Show("Website not found"); } } }
I call these methods in the Install event of the installer as follows..

public override void Install(IDictionary stateSaver) { .......CreateAppPoolIIS7();AssignIIS7AppPoolToVirDir();
The assigned app pool is reflected in the IIS as long as the control is in the custom action project. The apppool resets back to the default selected at the start of the installer once the setup exits the custom action project.

It would be grateful if some one could help.
When you fail to plan, you are planning to fail.