gpt4 book ai didi

c# - IdentityServer 4 Https 通过自签名证书

转载 作者:行者123 更新时间:2023-12-04 22:42:26 31 4
gpt4 key购买 nike

在本地,我有一组 Web 应用程序都可以通过一次登录访问。
为此,我采用了 Identity Server 4。
一旦应用程序发布在本地服务器上,无法远程访问,我就通过 openssl 生成了一个 SSL 证书并设置 IIS 以使用它。
特别是,我的机器可以通过本地 dns 访问。
例如我的机器有 ip: 192.168.15.3 并且别名是 app.server.lan
如果我连接到该站点的主页 (app.server.lan),Google Chrome 会检测到该站点是安全的。
但是当我尝试访问应用程序然后启动应用程序和身份服务器之间的连接时,我得到一个错误页面,日志中出现以下错误:

2021-02-04 14:09:04.6785|1|ERROR|Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware|An unhandled exception has occurred while executing the request. 
System.InvalidOperationException: IDX20803: Unable to obtain configuration from: '[PII is hidden]'.
---> System.IO.IOException: IDX20804: Unable to retrieve document from: '[PII is hidden]'.
---> System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
PPI 是隐藏的:.well-known/openid-configuration 如果我通过浏览器检查,它是可见的。
我该如何解决?
我可以在没有 https 的情况下使用 IdentityServer 4 吗?

你看到黑线的地方是 app.server.lan
5000 是身份服务器端口
443 是主应用程序端口
5001 到 5005 是其他应用程序端口

最佳答案

以下是从商店获取证书的代码:

X509Certificate2 cert = null;
using (var certStore = new X509Store(StoreName.My, StoreLocation.LocalMachine))
{
certStore.Open(OpenFlags.ReadOnly);
var certCollection = certStore.Certificates.Find(
X509FindType.FindByThumbprint,
"<THUMBPRINT>", // Change this with the thumbprint of your certifiacte
false);

if (certCollection.Count > 0)
{
cert = certCollection[0];
}
}
if(cert == null)
{
// If the certificate is not installed, you might be in development and want to ise the developer credebntials
services.AddIdentityServer()
.AddDeveloperSigningCredential();
}
else
{
services.AddIdentityServer()
.AddSigningCredential(cert);
}
确保运行 IdentityServer 应用程序的应用程序池身份可以访问私钥。如果没有,请给予许可。
在 iis 应用程序池高级设置中将加载用户配置文件设置为“true”。

关于c# - IdentityServer 4 Https 通过自签名证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66046362/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com