.Net Core project start-up mode

This paper smaller space, explain how to start the project from the command line

Then the last chapter of WebApi Core ( https://www.cnblogs.com/zousc/p/12420998.html ), we've got Hello this controller, and there are RESTFull Get method, as well as define their own name SayHello method. 

The way we usually start the project is launched directly from VS

Command line start:

First, open the DOS window to enter commands in the project

Right-click the project = "Open the file in the File Explorer folder =" bin \ Debug \ netcoreapp2.1

 

You can switch directly in the address bar enter cmd in cmd into the current directory and enter the command in a DOS window:

dotnet WebApplication1.dll

  

Then we get from listening port access under

If we want the project to run at a specified port it? Only you need to add parameters on it!

dotnet WebAppliction1.dll --urls="http://*:8888" --ip="127.0.0.1" --port="8888"

  

So that you can go to the browser to access port 8888, however, it is this:

  Roll scene .PNG

 

Now add a line of code to Program.cs

 

 

This line expressed support for the command line to start, you can obtain ip port via the command line to start Oh

 

string ip = Configuration["ip"];

int port = int.Parse(Configuration["port"]);

  

 

PS: can start from a configuration file to set the port, designated port, except using the command line can be dynamically assigned port.

 

 

 

Guess you like

Origin www.cnblogs.com/zousc/p/12421131.html
Recommended