日期:2014-05-18  浏览次数:20796 次

卸载时删除虚拟目录,出错,恳请高手相助
C# code

               public override void Uninstall(System.Collections.IDictionary savedState)
        {

            base.Uninstall(savedState);
            //卸载时删除虚拟目录,有问题
            System.DirectoryServices.DirectoryEntry dirroot = new DirectoryEntry("IIS://localhost/W3SVC/1/ROOT");
            StringBuilder sb = new StringBuilder();
            sb.Append(GetCurrentDomainPath());
            string sbb = sb.ToString();
            MessageBox.Show(sbb);
            string sweb = System.Web.HttpContext.Current.Server.MapPath("/");
            MessageBox.Show(sweb + sbb);
            DirectoryEntry Dirport = dirroot.Children.Find(sweb, sbb);
            Dirport.Invoke("AppDelete", true);
            dirroot.CommitChanges();
……………………


以上代码,能正常编译,只是卸载时出错,提示:未能实现该方法……

------解决方案--------------------
public override void Uninstall(System.Collections.IDictionary savedState)
{
System.Diagnostics.Debugger.Launch ();
base.Uninstall(savedState);
//卸载时删除虚拟目录,有问题
System.DirectoryServices.DirectoryEntry dirroot = new DirectoryEntry("IIS://localhost/W3SVC/1/ROOT");
StringBuilder sb = new StringBuilder();
sb.Append(GetCurrentDomainPath());
string sbb = sb.ToString();
MessageBox.Show(sbb);
string sweb = System.Web.HttpContext.Current.Server.MapPath("/");
MessageBox.Show(sweb + sbb);
DirectoryEntry Dirport = dirroot.Children.Find(sweb, sbb);
Dirport.Invoke("AppDelete", true);
dirroot.CommitChanges();
……………………

单步调试一下: