将IdentityServer 4部署到Azure VM时找不到证书

Riz*_*ban 5 azure .net-core identityserver4

我在将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()
Run Code Online (Sandbox Code Playgroud)

这将适用于本地开发计算机,我无法弄明白为什么.我在VM上的My(本地计算机)存储上安装了证书.

任何人都可以帮助这个.谢谢.

Riz*_*ban 9

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

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()
Run Code Online (Sandbox Code Playgroud)

现在看看这个问题.

好的,所以问题是阅读证书的许可.我们只需要转到证书并为IIS_IUSRS 授予Read(仅限).

现在它有效.

  • @Ruskin只去证书店.右键单击证书,然后选择"所有任务" - >"管理私钥".我希望有所帮助. (2认同)

Rus*_*kin 5

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

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

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

以上摘自这里