【问题标题】:Using https with IdentityServer4 quickstart hangs将 https 与 IdentityServer4 快速入门一起使用会挂起
【发布时间】:2017-02-26 17:16:40
【问题描述】:

我正在尝试学习 IdentityServer4,因此我从 https://identityserver4.readthedocs.io/en/dev/quickstarts/0_overview.html 此处的文档开始,并以 https://identityserver4.readthedocs.io/en/dev/quickstarts/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 无法工作吗?

【问题讨论】:

  • 当您在浏览器中访问站点和发现文档时会发生什么?任何给您提示的 asp.net 日志(提高日志级别以进行跟踪)
  • 在 Visual Studio 中启动解决方案后,我在浏览器中转到 localhost:44384/.well-known/openid-configuration,它只是说“无法访问此站点。localhost 响应时间太长。”开发人员工具显示 ERR_TIMED_OUT。有趣的是,我从github.com/IdentityServer/IdentityServer4.Samples 下载了样本并尝试了相同的测试。我从http切换到https,同样的事情发生了。我会查看日志,看看是否有任何帮助。

标签: https asp.net-core identityserver4


【解决方案1】:

看来问题出在控制台托管上。只要我在 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 中进行托管以继续前进。

【讨论】:

猜你喜欢
  • 2018-12-08
  • 2019-06-03
  • 1970-01-01
  • 2021-06-06
  • 2018-11-15
  • 1970-01-01
  • 2018-01-06
  • 2021-01-20
  • 1970-01-01
相关资源
最近更新 更多