2

我正在尝试学习 IdentityServer4,所以我从这里的文档开始https://identityserver4.readthedocs.io/en/dev/quickstarts/0_overview.html并以这个https://identityserver4.readthedocs.io/en/dev/结束快速入门/1_client_credentials.html

只要我使用http,一切都很好,但是一旦我切换到使用https,客户端测试器中的第一行代码

var disco = await DiscoveryClient.GetAsync("https://localhost:44384");

挂起并最终获得任务取消异常。

如果我只是将所有内容切换回 http,它就会重新开始工作。

在实际的 IdentityServer 解决方案中,我在 launchSettings.json 中更改了 applicationUrl 和 launchUrl:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "https://localhost:44384/",
      "sslPort": 44384
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "Mvcg.IdentityServer": {
      "commandName": "Project",
      "launchUrl": "https://localhost:44384",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

和 Program.cs 中的 .UseUrls

public static void Main(string[] args)
{
    var host = new WebHostBuilder()
        .UseKestrel()
        .UseUrls("https://localhost:44384")
        .UseContentRoot(Directory.GetCurrentDirectory())
        .UseIISIntegration()
        .UseStartup<Startup>()
        .Build();

    host.Run();
}

在客户端解决方案中,如上所述,我将调用发现端点的代码更改为使用 https 而不是 http

var disco = await DiscoveryClient.GetAsync("https://localhost:44384");

需要明确的是,只需将所有注释的项目从 http 和 https 更改为 http,但不适用于 https。我的两次测试之间没有其他变化。

有什么我遗漏的东西导致 https 无法工作吗?

4

1 回答 1

0

看起来问题出在控制台托管上。只要我在 IIS Express 中运行 IdentityServer 主机,一切正常。每次我尝试将其切换到控制台托管时,它都会失败。主机控制台中显示的错误是:

info: Microsoft.AspNetCore.Server.Kestrel[17]
      Connection id "0HKVQ4SEO0GOI" bad request data: "The input string contains non-ASCII or null characters."
Microsoft.AspNetCore.Server.Kestrel.BadHttpRequestException: The input string contains non-ASCII or null characters.
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIteratorExtensions.GetAsciiString(MemoryPoolIterator start, MemoryPoolIterator end)
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame.TakeStartLine(SocketInput input)
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame`1.<RequestProcessingAsync>d__2.MoveNext()
warn: Microsoft.AspNetCore.Server.Kestrel[0]
      Connection processing ended abnormally
Microsoft.AspNetCore.Server.Kestrel.BadHttpRequestException: The input string contains non-ASCII or null characters.
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure.MemoryPoolIteratorExtensions.GetAsciiString(MemoryPoolIterator start, MemoryPoolIterator end)
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame.TakeStartLine(SocketInput input)
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame`1.<RequestProcessingAsync>d__2.MoveNext()

不确定如何修复该错误,所以现在,我只需要在 IIS Express 中托管以继续前进。

于 2016-10-22T03:00:40.667 回答