.NET Core Access Site Externally?

2019-08-21 09:48发布

问题:

When I start my .NET Core app in VS 2019 using Kestrel in debug mode I can only access as https:// localhost:5001. When I try to replace localhost with my fqdn of my computer I get "Site cannot be reached". So actually it would be the computer and domain name so https:// win7.int.com:5001. I want to do this so that I can access the site from a different machine. If it doesn't work on my own machine this way I doubt it would on another. Now ideally I would have several apps under this main page (like app1, app2, etc.). URLs would be https:// win7.int.com/app1:5001 and https:// win7.int.com/app2:5001 and so on and so forth.

Excuse me I have a grails background and when an app starts on localhost I can just replace localhost with my computer name and it works. What do I need to do to make this work in .NET Core without going through IIS? Want to use Kestrel.

回答1:

By default Kestrel only binds to http://localhost:5000 and https://localhost:5001

If you want to change this you can configure the IP addresses or host addresses with ports and protocols that the server should listen on for requests by using the UseUrls method:

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args).UseKestrel().UseUrls("http://*:5000;https://*:5001")
.UseStartup<Startup>();