问题可能是由于容器中缺少密钥,需要在容器中添加密钥。具体解决方法是在Dockerfile中添加以下代码:
RUN dotnet dev-certs https
ENV ASPNETCORE_URLS=https://+;http://+
ENV ASPNETCORE_HTTPS_PORT=5001
ENV ASPNETCORE_ENVIRONMENT=Development
RUN mkdir -p /https
RUN dotnet tool install --global dotnet-certificate-tool
RUN dotnet certificate new -p password -v -n MyCertificate -c "CN=localhost"
RUN dotnet dev-certs https --clean
RUN dotnet dev-certs https -ep /https/aspnetapp.pfx -p password
然后在启动容器时,将创建的证书映射到容器中。
docker run -it -p 5001:80 -p 5000:443 -v ${PWD}/https:/https/ -e ASPNETCORE_Kestrel__Certificates__Default__Password=password -e ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx aspnetapp
另外,需要在应用程序中添加以下代码,以便在启动应用程序时从证书中加载密钥。
services.AddDataProtection()
.PersistKeysToFileSystem(new DirectoryInfo(@"\keys"))
.ProtectKeysWithCertificate("thumbprint");
上一篇:ASP.NETCoreJWT身份验证Audience属性解释
下一篇:ASP.NETCoreJWT授权失败,显示“AuthenticationScheme:Bearerwasnotauthenticated”。