简体   繁体   English

从IIS7中删除应用程序c#

[英]Remove application from IIS7 c#

I am trying to remove an application from the default web site in IIS7 during uninstallation. 我试图在卸载过程中从IIS7中的默认网站中删除一个应用程序。 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). 该代码确实假设您正在从Default Web Site的根目录(IIS编号#1)中删除应用程序/MyApplication

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM