使用https与IdentityServer4快速入门挂起

时间:2016-10-17 16:17:11

标签: https asp.net-core identityserver4

我正在尝试学习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不起作用的内容?

1 个答案:

答案 0 :(得分: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中托管以继续前进。