当 IIS 中具有通配符 SSL 证书的网站时,如何删除该网站?

发布于 2024-12-14 06:17:45 字数 1194 浏览 0 评论 0原文

我们正在开发 SaaS 解决方案,并希望自动创建和删除系统实例。此过程中的一个步骤是删除 IIS 站点,但事实证明这是相当困难的。

问题是我们对所有站点使用通配符 SSL 证书,如果您尝试以正常方式删除站点的 HTTPS 绑定,它将删除所有站点的绑定。这是因为绑定有两个组件,其中之一在所有站点之间共享。这就是 IIS 的工作原理。根据网上的说法,您可以通过手动编辑 applicationHost 文件或使用 appcmd.exe 控制台应用程序删除站点来解决此问题,因为它不使用 IIS 依赖的 WMA api。

我试图开始工作的解决方案是从我的管理网站内运行命令行应用程序,但我遇到了困难。以下代码显示了我想要执行的操作,但我总是收到错误代码 1168(ERROR_NOT_FOUND)。我不确定这意味着什么,但如果我直接在控制台中运行相同的命令,它会按预期工作。

internal void DeleteSite(string iisName)
{
    // Impersonation of system admin user
    using (Permission.Elevate())
    {
        ProcessStartInfo start = new ProcessStartInfo();
        start.Arguments = string.Format(@"delete site ""{0}""", iisName);
        start.FileName = @"C:\Windows\System32\inetsrv\appcmd.exe";
        start.WindowStyle = ProcessWindowStyle.Hidden;
        start.CreateNoWindow = true;

        using (Process proc = Process.Start(start))
        {
            proc.WaitForExit();

            var exitCode = proc.ExitCode;
            if (exitCode > 0)
                throw new Exception("Error code " + exitCode);
        }
    }
}

所以这个问题有三个方面。有没有更好的整体解决方案(必须是全自动的)?如果不是,我在上面的代码中做错了什么?如果一切都失败了,我可以做什么来调试控制台应用程序的错误代码?

We're working on a SaaS solution and would like to automate the creation and deletion of system instances. One step in this process is to delete the IIS site but it has proved to be quite difficult.

The problem is that we use a wildcard SSL certificate for all the sites, and if you try to delete the HTTPS binding for the site in the normal way, it will delete the binding for all the sites. This is because the binding has two components, one of which is shared between all the sites. This is just how IIS works. According to the web, you can solve this by either editing the applicationHost file manually or by using the appcmd.exe console app to delete the site, as it does not use the WMA api that IIS relies on.

The solution I'm trying to get to work is running the command line app from within my administration website, but I've hit a wall. The following code shows what I'm trying to do, but I always get the error code 1168, for ERROR_NOT_FOUND. I'm not sure what that means, but if I run the same command directly in the console it works as expected.

internal void DeleteSite(string iisName)
{
    // Impersonation of system admin user
    using (Permission.Elevate())
    {
        ProcessStartInfo start = new ProcessStartInfo();
        start.Arguments = string.Format(@"delete site ""{0}""", iisName);
        start.FileName = @"C:\Windows\System32\inetsrv\appcmd.exe";
        start.WindowStyle = ProcessWindowStyle.Hidden;
        start.CreateNoWindow = true;

        using (Process proc = Process.Start(start))
        {
            proc.WaitForExit();

            var exitCode = proc.ExitCode;
            if (exitCode > 0)
                throw new Exception("Error code " + exitCode);
        }
    }
}

So the question is threefold. Is there a better overall solution (must be fully automated)? If not, what am I doing wrong in the above code? And if all else fails, what can I do to debug error codes from console apps in general?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文