简体   繁体   中英

Can't Load a .Net Core 3.0 Web App Running From CLI

Issue:

I have a.Net Core 3.0 app that I'm unable to load in a browser ONLY when running it using the Mac OS X CLI , like so:

$ dotnet new webapp
$ dotnet watch run
watch : Started
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
      User profile is available. Using '/Users/<user>/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: /Users/<user>/Sandbox/coreapp3test

So everything looks good at this point, except when opening the URL in a browser I receive:

This site cannot be reached

localhost unexpectedly closed the connection.

UPDATE:

I think it has something to do with HTTPS protocol. Navigating to http://localhost:5000 does render an https redirect. So the server is actually listening...

info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
      Request starting HTTP/1.1 GET http://localhost:5000/
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
      Request finished in 9.6705ms 307

UPDATE 2:

Furthermore, removing the app.UseHttpsRedirection(); from the Configure method of startup.cs and then navigating to http://localhost:5000 renders the page correctly, while https://localhost:5001 still fails.

I've opened a ticket on GitHub to track the issue.

Notes:

  • I can run the app in VS Code , so the runtime must be installed correctly
  • .NET Core 2.2 apps work fine with the CLI - I can run them from the CLI without issue. So it appears isolated to 3.0
  • The Windows CLI appears to work without issue
  • I've also tried the following, without success:
    • Removing bin/ and obj/ and restoring / building again
    • Re-installing the SDK - same result
    • Disabling firewall (in case that was blocking the connection)
    • Generating multiple web project types (eg angular, mvc, etc.) to see if it was related to the template

System Info:

$ dotnet --info

.NET Core SDK (reflecting any global.json):
 Version:   3.0.100
 Commit:    04339c3a26

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.14
 OS Platform: Darwin
 RID:         osx.10.14-x64
 Base Path:   /usr/local/share/dotnet/sdk/3.0.100/

Host (useful for support):
  Version: 3.0.0
  Commit:  7d57652f33

.NET Core SDKs installed:
  2.1.300 [/usr/local/share/dotnet/sdk]
  2.1.402 [/usr/local/share/dotnet/sdk]
  2.1.505 [/usr/local/share/dotnet/sdk]
  3.0.100 [/usr/local/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.9 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.9 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.9 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

running from vs code does dotnet run . It appears that the watch command has an infinite loop trying to watch some files that are contantly changing. This may be due to for example reloadOnChange option in configurationBuilder .

configurationBuilder.AddJsonFile(
            "appsettings.json",
            optional: false,
            reloadOnChange: true) 

v3.1 Update

This has been resolved in v3.1.x, per the dotnet team on Github .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM