【问题标题】:IdentityServer4 Quickstart UI only runs with SDK, but doesn't work with runtimeIdentityServer4 快速入门 UI 仅与 SDK 一起运行,但不适用于运行时
【发布时间】:2019-06-03 09:36:14
【问题描述】:

我已经设置了一个 IdentityServer4 服务器,如果我在主项目目录中执行 dotnet run,它就会运行,但如果我发布它然后尝试使用 dotnet 运行 dll,它就无法正常运行:

dotnet publish
cd bin/Debug/netcoreapp2.2/publish
dotnet MyIdentityServer.dll

我正在使用 ASP.Net Core 2.2。我已经在我的常规开发环境以及使用 SDK 和运行时 docker 容器中进行了尝试。它可以在我的常规环境和 SDK 容器中使用 SDK。在我的常规开发环境或运行时容器内部使用运行时时,它不起作用。

当我运行 dotnet 时,我可以看到 IdentityServer 的 Web UI,但是当我运行已发布的 DLL 时,启动没有相同的 IdentityServer 启动消息,并且在它说它正在运行之后,我无法连接到它说应该运行的端口上的服务器。

这是在执行dotnet run 后启动消息的样子:

MacBook-Pro:MyIdentityServer XXXXXXXXXX$ dotnet run
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
      User profile is available. Using '/Users/XXXXXXXXXX/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
info: IdentityServer4.Startup[0]
      Starting IdentityServer4 version 2.3.2.0
info: IdentityServer4.Startup[0]
      You are using the in-memory version of the persisted grant store. This will store consent decisions, authorization codes, refresh and reference tokens in memory only. If you are using any of those features in production, you want to switch to a different store implementation.
info: IdentityServer4.Startup[0]
      Using the default authentication scheme idsrv for IdentityServer
dbug: IdentityServer4.Startup[0]
      Using idsrv as default ASP.NET Core scheme for authentication
dbug: IdentityServer4.Startup[0]
      Using idsrv as default ASP.NET Core scheme for sign-in
dbug: IdentityServer4.Startup[0]
      Using idsrv as default ASP.NET Core scheme for sign-out
dbug: IdentityServer4.Startup[0]
      Using idsrv as default ASP.NET Core scheme for challenge
dbug: IdentityServer4.Startup[0]
      Using idsrv as default ASP.NET Core scheme for forbid
Hosting environment: Development
Content root path: /Users/XXXXXXXXXX/Projects/FirstIdentityServer4/src/MyIdentityServer
Now listening on: http://localhost:5000
Now listening on: https://localhost:5001
Application started. Press Ctrl+C to shut down.

以下是使用dotnet MyIdentityServer.dll 直接运行已发布的 DLL 后启动消息不工作时的样子:

MacBook-Pro:publish XXXXXXXXXXXX$ dotnet MyIdentityServer.dll
Hosting environment: Production
Content root path: /Users/XXXXXXXXXXX/Projects/FirstIdentityServer4/src/MyIdentityServer/bin/Debug/netcoreapp2.2/publish
Now listening on: http://localhost:5000
Now listening on: https://localhost:5001
Application started. Press Ctrl+C to shut down.

这是我的项目目录:

MacBook-Pro:MyIdentityServer XXXXXXXXX$ ls
Config.cs           appsettings.Development.json
Dockerfile          appsettings.json
MyIdentityServer.csproj     bin
Program.cs          obj
Properties          something.txt
Quickstart          tempkey.rsa
Startup.cs          wwwroot
Views

这是我执行dotnet publish 后的发布目录:

MacBook-Pro:publish XXXXXXXXXX$ ls
IdentityModel.dll           MyIdentityServer.pdb
IdentityServer4.Storage.dll     MyIdentityServer.runtimeconfig.json
IdentityServer4.dll         appsettings.Development.json
MyIdentityServer.Views.dll      appsettings.json
MyIdentityServer.Views.pdb      tempkey.rsa
MyIdentityServer.deps.json      web.config
MyIdentityServer.dll            wwwroot

我是发布不正确还是运行不正确?

【问题讨论】:

  • Dev 环境中尝试 dotnet run -c Release
  • 您还需要帮助吗?
  • 当我执行dotnet run -c Release 时,它使用的是项目目录中的 SDK,而不是使用发布目录中的运行时。在只有 dotnet 核心运行时的环境中,对 dotnet run 的任何调用都会失败。所以,是的,仍在寻找答案。更多信息在这里:docs.microsoft.com/en-us/dotnet/core/tools/…
  • 正在使用 AddDeveloperSigningCredential 可以添加 startup.cs

标签: identityserver4


【解决方案1】:

基于

MacBook-Pro:MyIdentityServer XXXXXXXXXX$ dotnet run
dbug: IdentityServer4.Startup[0]
      Using idsrv as default ASP.NET Core scheme for forbid
Hosting environment: Development

还有这个

MacBook-Pro:publish XXXXXXXXXXXX$ dotnet MyIdentityServer.dll
Hosting environment: Production

日志

dbug: IdentityServer4.Startup[0]

通常来自

services.AddIdentityServer();

所以我很高兴你在 IsDevelopment 中调用 AddIdentityServer

if (Environment.IsDevelopment())
{
    services.AddIdentityServer();
}

这就是为什么托管环境:生产 没有获取 IdentityServer 日志

【讨论】:

  • 不,不是这样。 services.AddIdentityServer() 位于该方法的顶层。我有更多信息...我可以访问 .well-known/openid-configuration,但无法访问快速启动 UI。所以我想我应该澄清我的原始陈述,我会修正标题......从项目目录执行“dotnet run”时,快速入门 UI 很容易获得,但在已发布的应用程序中不可用。我也会将其发布在 IdentityServer4 存储库中。
猜你喜欢
  • 2017-02-26
  • 1970-01-01
  • 1970-01-01
  • 2018-09-17
  • 2016-02-24
  • 2018-12-08
  • 2013-06-21
  • 2021-01-21
  • 2020-11-26
相关资源
最近更新 更多