开发者

Remove application from IIS7 c#

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 ;
myApplicat开发者_JAVA百科ion = 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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜