I am trying to remove an application from the default web site in IIS7 during uninstallation. Here's my code which does not work:
Microsoft.Web.Administration.ServerManager iisManager;
iisManager = new Microsoft.Web.Administration.ServerManager();
Microsoft.Web.Administration.Site defaultSite;
defaultSite = iisManager.Sites["Default Web Site"];
Microsoft.Web.Administration.Application myApplication ;
myApplication = defaultSite.Applications["MyApplication"];
defaultSite.Applications.Remove(myApplication );
iisManager.CommitChanges();
What is the right way to do this?
Thanks
This should do the trick:
using (ServerManager serverManager = new ServerManager())
{
Site site = serverManager.Sites["Default Web Site"];
Application application = site.Applications["/MyApplication"];
site.Applications.Remove(application);
serverManager.CommitChanges();
}
The code does make the presumption that you are deleting the application /MyApplication
from the root of the Default Web Site
(IIS number #1).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With