Is specifying the listening HTTP port via UseUrls the correct way?

Money Sets You Free picture Money Sets You Free · Sep 24, 2017 · Viewed 12.6k times · Source

I have successfully deployed an asp.net core mvc to windows iot core on my raspberry pi 3.

I am not sure whether specifying the listening HTTP port via invoking UseUrls as shown in the following snippet is the correct way.

namespace winiotrasp
{
    public class Program
    {
        // ... others ...

        public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                .UseUrls("http://*:80")
                .Build();
    }
}

Questions

Is specifying the listening HTTP port via UseUrls the correct way?

Note that If I don't specify as shown above, the default setting is http://localhost:5000 which makes the web server inaccessible from other devices.

Answer

Michael Xu - MSFT picture Michael Xu - MSFT · Sep 25, 2017

Yes, it is the correct way.The UseUrls method is for indicates the IP addresses or host addresses with ports and protocols that the server should listen on for requests. Please reference Hosting in ASP.NET Core. If you don't specify the the IP addresses or host addresses with ports, you can use cmdlet $env:ASPNETCORE_URLS="http://0.0.0.0:5000" to change the default setting, then run the web server and it will be inaccessible from other devices.