【问题标题】:Adding https binding from ASP.NET MVC application hosted从托管的 ASP.NET MVC 应用程序添加 https 绑定
【发布时间】:2020-01-24 17:45:32
【问题描述】:

我在 IIS 网站 TestWebsite 中托管了一个应用程序,并且我正在使用 Microsoft.Web.Administration 进行 IIS 自动化。

我必须对来自 TestWebsite

的 SAME 网站 TestWebsite 的绑定进行以下操作
  1. 将带有 SSL 证书的 HTTPS 绑定从同一应用程序添加到网站“TestWebsite”(添加绑定的代码将在同一“TestWebsite”中)
  2. 移除绑定。

我已经完成了以下代码,奇怪的是在 localhost 上它正在添加 https 绑定,但甚至在 ma​​nager.commitchange() 之前。此行在本地主机上引发异常,因此我删除了此行,但在 Windows Server 上,即使在成功运行代码后它也没有添加绑定。 (没有 commitchanges(),我不知道没有它如何在 localhost 上工作)

我在 localhost 上使用 IIS 10,在 staging 上使用 IIS 8.5,在生产上使用 IIS 8.0。

using (ServerManager iisManager = new ServerManager())
{
    var website = iisManager.Sites.Where(x => x.Name == "TestWebsite").FirstOrDefault();
    if (website != null)
    {
        var store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
        store.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadWrite);
        var pfxPath = Server.MapPath(model.PfxPath);
        var certificate = new X509Certificate2(pfxPath, password, X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet);
        store.Add(certificate);
        store.Close();
        var certHash = certificate.GetCertHash();

        string bindingInformation = string.Format("{0}:{1}:{2}", "*", "443", model.UserCustom);
        var binding = website.Bindings.Add(bindingInformation, certHash, store.Name);
        binding.Protocol = "https";
        store.Close();

        website.ApplicationDefaults.EnabledProtocols = "http,https";
        iisManager.CommitChanges();
    }
}

我在 iisManager.CommitChanges() 行收到以下错误

指定的登录会话不存在。它可能已经被终止。 (HRESULT 异常:0x80070520)

是否有一些权限相关的错误?我做错了什么?

您的帮助将不胜感激

谢谢你:) 丹尼尔·马利克

【问题讨论】:

  • 你曾经在哪里解决过这个问题?我在尝试为 https 绑定提交更改时收到相同的错误。

标签: c# asp.net-mvc iis iis-8 iis-10


【解决方案1】:

当管理员组没有访问权限时,IIS 将返回 0x80070520 错误 C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys。请尝试为您的管理员组授予完全控制权限。

https://www.cnblogs.com/ziye/p/9208353.html

https://blogs.msdn.microsoft.com/asiatech/2010/08/12/got-error-0x80070520-when-binding-certificate-to-web-site-on-iis-7/

【讨论】:

  • “对于您的管理员组”是什么意思?我进入了那个 MachineKeys 文件夹的属性,并且在安全性方面也向所有人和管理员授予了完全权限,但它仍然存在问题。 Microsoft.Web.Administration 版本 7 可以在 IIS 8 及更高版本上运行吗?
  • 我拥有管理员、管理员和所有人的完全权限,但仍然抛出同样的错误。
  • @DanyalMalik 你能在事件查看器中找到任何错误消息吗?此外,你能否尝试启用进程监视器并监视在尝试重现此问题时是否会在计数器中记录任何访问被拒绝错误. docs.microsoft.com/en-us/sysinternals/downloads/procmon
猜你喜欢
  • 2011-01-11
  • 2015-01-29
  • 1970-01-01
  • 1970-01-01
  • 2014-01-19
  • 2014-05-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多