HTTP 错误 500.30(Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException:系统找不到指定的文件。)

Lil*_*azi 3 iis asp.net-core

我正在尝试将 asp.net 核心 Web API 部署到 IIS。这个应用程序在 Visual Studio 上运行得非常好,当我使用 dotnet 命令运行 dll 时也是如此。此应用程序具有用于签署 JWT 令牌的证书。将应用程序部署到 IIS 后,我收到“HTTP 错误 500.30 - ANCM 进程内启动失败”,我检查了 Windows 日志,错误消息是

主机意外终止。Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: 系统找不到指定的文件。在 Internal.Cryptography.Pal.CertificatePal.FilterPFXStore(Byte[] rawData, SafePasswordHandle password, PfxCertStoreFlags pfxCertStoreFlags)......

我检查了文件路径和文件名一切都正确,但由于某些原因 IIS 无法加载找到证书文件。另外,我检查了许可,它看起来也不错。不知道为什么我收到此错误消息

此外,我使用 IIS 指向的 dotnet run 命令运行了相同的应用程序 dll 文件,但我没有收到任何错误。我只有在部署到 IIS 后才会收到此错误。

在 startup.cs 文件和配置方法上,我在这一行遇到错误。

var cert = new X509Certificate2("test_cert.pfx", pwdFrmVault);
Run Code Online (Sandbox Code Playgroud)

Lil*_*azi 6

我在搜索此错误并使用谷歌搜索后,此解决方案对我有用。IIS管理器->应用程序池->高级设置->在进程模型下,将用户配置文件加载为true。链接上的更多详细信息