将标识服务器 4 部署到 Azure VM 时找不到证书



我在将IdentityServer 4(ASP.NET Core 1.1)部署到Azure VM(Windows Server 2012 R2)时遇到此证书问题。

crit: IdentityServer4.Hosting.IdentityServerMiddleware[0]
Unhandled exception: Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: The system cannot find the file specified
at System.Security.Cryptography.CngKey.Open(String keyName, CngProvider provider, CngKeyOpenOptions openOptions)
at System.Security.Cryptography.CngKey.Open(String keyName, CngProvider provider)
at Internal.Cryptography.Pal.CertificatePal.GetPrivateKey[T](Func`2 createCsp, Func`2 createCng)
at Internal.Cryptography.Pal.CertificatePal.GetRSAPrivateKey()

这将在本地开发计算机上工作,我无法弄清楚原因。我在 VM 上的"我的(本地计算机)"存储上安装证书。

谁能帮忙。谢谢。

我在这里找到了解决方案:

http://www.daves-blog.net/post/2014/06/16/X509Certificate-The-System-cannot-find-the-file-specified.aspx

显然,我需要在应用程序池上启用加载用户配置文件。但是,错误现在更改为:

crit: IdentityServer4.Hosting.IdentityServerMiddleware[0]
Unhandled exception: Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: Keyset does not exist
at System.Security.Cryptography.CngKey.Open(String keyName, CngProvider provider, CngKeyOpenOptions openOptions)
at System.Security.Cryptography.CngKey.Open(String keyName, CngProvider provider)
at Internal.Cryptography.Pal.CertificatePal.GetPrivateKey[T](Func`2 createCsp, Func`2 createCng)
at Internal.Cryptography.Pal.CertificatePal.GetRSAPrivateKey()

现在看这个问题。

好的,所以问题是读取证书的权限。我们所要做的就是转到证书并授予IIS_IUSRS只读()。

现在它起作用了。

如果有人想知道如何让 IIS 用户访问证书

  1. 创建/购买证书。确保它有私钥。
  2. 将证书导入"本地计算机"帐户。最好使用证书 MMC。确保选中"允许导出私钥">
  3. 基于此,IIS 7.5 应用程序池的标识使用以下标识之一。

    • IIS 7.5 网站在 ApplicationPoolIdentity 下运行。打开 MMC => 添加证书(本地计算机)管理单元 => 证书(本地计算机)=> 个人 => 证书 => 右键单击感兴趣的证书 => 所有任务 => 管理私钥 => 添加IIS AppPoolAppPoolName并授予它Full control。将">AppPoolName"替换为应用程序池的名称(有时IIS_IUSRS
    • )
    • IIS 7.5 网站在网络服务下运行。使用证书 MMC,将"网络服务"添加到"本地计算机\个人"中证书的完全信任。
    • IIS 7.5 网站在"MyIISUser"本地计算机用户帐户下运行。使用证书 MMC,将"MyIISUser"(新的本地计算机用户帐户)添加到"本地计算机\个人"中证书上的完全信任。

以上摘自此处。

最新更新