Kestrelhttpserver: Kestrel config binder should understand * and localhost

Created on 1 Jun 2017  路  12Comments  路  Source: aspnet/KestrelHttpServer

_From @Tratcher on April 27, 2017 17:0_

The templates are going to enable SSL via config in dev and production. They need to set up the rest of the endpoints when they do this. https://github.com/aspnet/MetaPackages/pull/44 added the ability to bind to IPs and ports, but that makes for a poor user experience. In dev the templates want localhost, but will have to specify 127.0.0.1 (and ::1) if they want IPv6 support. In production they'll need to specify a public IP (0.0.0.0 and ::0).

Config should allow localhost that binds to 127.0.0.1 and ::1, and * that binds to 0.0.0.0 and ::0, using the same logic that kestrel applies to UseUrls values. Even better, implement this in Kestrel with a Listen that takes the string ip/host so you don't have to duplicate all of the logic.

_Copied from original issue: aspnet/MetaPackages#73_

3 - Done bug

Most helpful comment

@glennc This issue is also the first in a series of issue that prevents enabling docker for out templates that use authentication.

I'm also seeing a port forwarding issue with the "dotnet new web" template and the current docker image "microsoft/dotnet"

I also see the warning with "Unable to bind to http://localhost:5000 on the IPv6 loopback interface: (Error -99 EADDRNOTAVAIL address not available)".

root@24cf43adf652:~# dotnet new web -o www
Content generation time: 74.6508 ms
The template "ASP.NET Core Empty" created successfully.
root@24cf43adf652:~# cd www/
root@24cf43adf652:~/www# dotnet restore
  Restoring packages for /root/www/www.csproj...
  Generating MSBuild file /root/www/obj/www.csproj.nuget.g.props.
  Generating MSBuild file /root/www/obj/www.csproj.nuget.g.targets.
  Writing lock file to disk. Path: /root/www/obj/project.assets.json
  Restore completed in 680.72 ms for /root/www/www.csproj.

  NuGet Config files used:
      /root/.nuget/NuGet/NuGet.Config

  Feeds used:
      https://api.nuget.org/v3/index.json
root@24cf43adf652:~/www# dotnet run
warn: Microsoft.AspNetCore.Server.Kestrel[0]
      Unable to bind to http://localhost:5000 on the IPv6 loopback interface: (Error -99 EADDRNOTAVAIL address not available)
Hosting environment: Production
Content root path: /root/www
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.

My current solution is amending the Program.cs file to include .UseUrls("http://*:5000") which fixes port forwarding and removes the warning

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

    host.Run();
}

All 12 comments

_From @Tratcher on April 27, 2017 17:14_

@danroth27

@muratg @DamianEdwards @Eilon We chatted about this one and we think we need to get this into preview1. @muratg please assign.

We chatted even more and the fix is more complicated than we want to take right now. We'll have to tell folks to browse to localhost.

_From @muratg on May 25, 2017 22:14_

Assigning to @cesarbs for post preview2.

@glennc This issue is also the first in a series of issue that prevents enabling docker for out templates that use authentication.

_From @Tratcher on June 1, 2017 16:15_

Note this code is moving to Kestrel. https://github.com/aspnet/KestrelHttpServer/pull/1878

@glennc This issue is also the first in a series of issue that prevents enabling docker for out templates that use authentication.

I'm also seeing a port forwarding issue with the "dotnet new web" template and the current docker image "microsoft/dotnet"

I also see the warning with "Unable to bind to http://localhost:5000 on the IPv6 loopback interface: (Error -99 EADDRNOTAVAIL address not available)".

root@24cf43adf652:~# dotnet new web -o www
Content generation time: 74.6508 ms
The template "ASP.NET Core Empty" created successfully.
root@24cf43adf652:~# cd www/
root@24cf43adf652:~/www# dotnet restore
  Restoring packages for /root/www/www.csproj...
  Generating MSBuild file /root/www/obj/www.csproj.nuget.g.props.
  Generating MSBuild file /root/www/obj/www.csproj.nuget.g.targets.
  Writing lock file to disk. Path: /root/www/obj/project.assets.json
  Restore completed in 680.72 ms for /root/www/www.csproj.

  NuGet Config files used:
      /root/.nuget/NuGet/NuGet.Config

  Feeds used:
      https://api.nuget.org/v3/index.json
root@24cf43adf652:~/www# dotnet run
warn: Microsoft.AspNetCore.Server.Kestrel[0]
      Unable to bind to http://localhost:5000 on the IPv6 loopback interface: (Error -99 EADDRNOTAVAIL address not available)
Hosting environment: Production
Content root path: /root/www
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.

My current solution is amending the Program.cs file to include .UseUrls("http://*:5000") which fixes port forwarding and removes the warning

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

    host.Run();
}

@pflannery try using the microsoft/aspnetcore image instead. This image is designed to host web apps, and contains settings, such as ASPNETCORE_URLS, that solve this issue for you.

@natemcmaster Thanks. I just tried that and get blocked when running dotnet --info

root@29095298643c:~# dotnet --info
Did you mean to run dotnet SDK commands? Please install dotnet SDK from:
  http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409

Following that link didnt seem to solve my issue so I tried to run through the linux debian sdk commands here https://www.microsoft.com/net/core#linuxdebian but still same problem.

Following https://www.microsoft.com/net/core#dockercmd gets me as far as the EADDRNOTAVAIL error I reported above.

@pflannery If you need to build an app in the container, use microsoft/aspnetcore-build. Let's continue this discussion here https://github.com/aspnet/aspnet-docker as this is separate from the intent of this issue.

This issue was moved to aspnet/AspNetCoreModule#136

I think this was closed in error, the EADDRNOTAVAIL issue was unrelated to the original configuration issue.

Was this page helpful?
0 / 5 - 0 ratings