Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
496 views
in Technique[技术] by (71.8m points)

asp.net core - How to access HTTP port 5001 from public internet

I have Windows Server 2016 Data center x64, .NET Core SDK 5.0 preview, Microsoft SQL Server 2019

enter image description here

On server: https://localhost:5001/publisher/all ok

On server https://127.0.0.1:5001/publisher/all ok

On server: Firewall Open port 5000-6000 outbound

from my computer (or any PC on the world) https://45.118.145.72:5011/publisher/all not ok

enter image description here

How to access https://45.118.145.72:5011/publisher/all from public internet?

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Asp.NET core apps bind to the "localhost" network interface with default settings. This network interface is not available from other hosts.

You can modify this using UseUrls()during host setup.

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.UseStartup<Startup>();
            webBuilder.UseUrls("http://0.0.0.0:5001");
        });

Examples:

webBuilder.UseUrls("http://127.0.0.1:5001"); // only from localhost
webBuilder.UseUrls("http://localhost:5001"); // only from localhost
webBuilder.UseUrls("http://0.0.0.0:5001");   // allow all hosts

Docs: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-3.1#kestrel-in-aspnet-core-apps


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...