IdentityServer4 Quickstart UI仅与SDK一起运行,但不适用于运行时

时间:2019-01-08 16:40:58

标签: identityserver4

我已经设置了一个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

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

1 个答案:

答案 0 :(得分:0)

基于

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日志