10.ASP.NET Core launchSettings.json file

        This article, I will lead them to learn ASP.NET Core in launchSettings.json file. To learn it, we open a blank template built before ASP.NET Core project.

image

        As you can see from the picture above, the properties of our project has a launchSettings.json file. So let's learn it together this important document.

launchSettings.json file

        When we use the Visual Studio .NET Core CLI or run project, will be used to LaunchSettings.json file these settings.

        You especially need to keep in mind is: LaunchSettings.json file, just on the local computer. This is meant, when we released ASP.NET Core applications to a production environment, this file is not needed .

        When you have some special settings, you need your applications to use when the release deployment, then you should write to these settings in appSettings.json file. In general, ASP.NET Core, the configuration files are written in appsettings.json file. I talked about appsettings.json will file in the next article.

Configuration information launchSettings.json file

When you open launchSettings.json file, you will see the configuration information:

image

        In the picture above, you can see the profiles have two parts, one is IIS Express, there is a EmptyTemplateCoreApp.

        You need to remember is: when you press CTRL + F5 or press F5, the time to run the program , then the profiles in " commandName": "IIS Express " will be used. At the same time, when you use. When NET Core CLI run ASP.NET Core application , then the profile of the "commandName": "Project " This configuration will be used.

      However, when you want to select which profile will be used, you can select the drop-down box option in Visual Studio:

image

CommandName attribute value, the following can be several:

  1. IIS Express
  2. IIS
  3. Project

CommandName value of the property, as well as the project file AspNetCoreHostingModel value of the node will determine the application server using an internal or an external server (also known as a reverse proxy server). Consider the following table.

c-users-pranaya-pictures-compressed-internal-and

Configure Startup class method modifies

Configure modification method to display the running time of the work process in the browser:

image

Case number one:

When we use the command-line properties Project as the value of the time, ASP.NET Core will ignore the value AspNetCoreHostingModel node. Then Kestrel is the only server to server hosting to run the program, as well as handling HTTP requests. We do this: Select [EmptyTemplateCoreApp]

image

Then run the application:

image

Task Manager can be seen: the host using ApplicationFrameHost.exe

imageNow a change of project files, add in it: <AspNetCoreHostingModel> InProcess </ AspNetCoreHostingModel>

image

The result is still the same run, this is because: CommandName property is Project, and then it will ignore the configuration AspNetCoreHostingModel node, this time, Kestrel is the only server to host the program and processing HTTP requests. It also verified the first table .

Case II:

CommandName select IIS Express, and AspNetCoreHostingModel choose InProcess, then IIS Express will be the only server to host the procedures for handling HTTP requests.

image

Run the program: You can see this time, the process name is iisexpres up.

image

Case 3:

ComandName select IIS Express, AspNetCoreHostingModel select OutOfProcess. This time, ASP.NET Core use IIS Express as an external server, Kestrel server as an internal server. IIS Express will external server receives the HTTP request, and passed to the internal server to handle. Let's verify:

image

Run the program:

image

image

How to get CommandName set up using the graphical user interface in Visual Studio?

Right project - site Properties, and then find Debug, saw:

image

Use graphical interface, we can also change the settings in the launchSettings.json. Here you can see the "Environment Variables ASPNETCORE_ENVIRONMENT value" is " Development ", when you run the project, you can change to " Staging " or " Production's ", of course, you can also add your own environment variables. And you can also do something based on environmental variables, such as:

image

The picture above, it will check whether the development environment, and if so, on the implementation of the page under abnormal development environment. In a later article, we will be talked about more environmental variables.

Next article that will be talked about ASP.NET Core appsettings.json file. In this article I have introduced launchSettings.json file details, we clear?

Guess you like

Origin www.cnblogs.com/caofangsheng/p/12640967.html