In this section the instructor covers how to run ASP.NET applications from Visual Studio and the command line.
- [Instructor] With .NET Core applications there are additional ways that you can execute from either inside Visual Studio or outside Visual Studio. So in Visual Studio, we can launch them using either IIS Express or Kestrel and the profiles as in what port and everything else is configured through the launchsettings.JSON file. You can run from the command prompt using dot net run, and you can also run it from the package manager console, which is essentially a command prompt with power shell.
But there's an issue with stopping the service. So let's look at this now. So we'll just use the 1.0 application. And there's a couple changes that you'll see right off the bat. If I click on the down arrow next to the run button, I see IIS Express and then I see my project name. Now the project name if I switch to that is actually going to be run using Kestrel. Under properties, the launchsettings.JSON file, here we have IIS settings at the top, configures the URL on line six.
Says I'm not using SSL and what authentication I have set up. And then I set the environment variable. And we'll discuss that in great detail later. But this is IIS Express. And then the Kestrel version is here starting on line 18 where the name just defaulted to the name of your project. Again sets the environment and sets the URL. And we can see that it is a slightly different port than on line six.
Here we have 62174 and 62175. So let's go ahead and run it, make sure everything is working. And this will start on port 62175 because I have the Kestrel options selected with the run toolbar button. Okay here we have our application. It's pretty simple. We have some different menus across the top. We can click on one of these that will bring up the products in that category.
Now an interesting side note, since I am running in Kestrel, what Visual Studio is doing is actually running from a command prompt for us. And what we see is all the logging that gets done. And we'll talk about logging. But you will see this command window open up and continue to run. Now we can also run straight out of IIS. We won't see the command window when we do that. And if we run out of IIS it runs as we would expect.
We can also run directly from a command window. So if we open the file in Explorer, we can just type in command, it'll put us right into the right directory. And from here, I can just type dot net run that we have to be in the directory of the CS prod file of the ASP.NET Core app which we are. And then we'll see the same output in the command window as we saw when we ran using the Kestrel option in Visual Studio and is now listening on this port.
We can cut and paste that into a browser. And we'll see the same thing we just saw. And the application is started. We want to shut it down. We just hit Control C. And we're back to the regular command prompt. Now we can also run it from package manager console. We want to change into the directory that has the CS prod file for per every C app, which is by store.
Underscore V 10. And once we are here, we just type dot net run. We'll see the same output coming through. It'll prompt us to do a Control C to shut down. Unfortunately it's not going to want to let us to do that. Application started, we can browse the URL, beta Control C a whole bunch of times. Doesn't want to stop. Hit the stop button. Doesn't want to stop. What we actually need to do then is bring up task manager, find dot net.
Let's just go ahead and sort this by alphabetical. And the executable is actually called DOT NET. Right here. And we end that task. So a little quirky when running from package manager console, so any unsolvable problem. Then when we get into Docker, there is a little bit different option here. We have the option up top that says Docker.
And again, we're going to cover this more when we get into the 2.0 section. But we have a Docker compose file, and this is actually our startup project. So if I run this, it'll actually load a Docker container and then execute in a browser window. So those are different ways that you can execute ASP.NET Core applications.
- Running and debugging ASP.NET Core applications
- Pros and cons of migrating existing applications to ASP.NET Core.
- Built-in dependency injection
- Environment awareness and app configuration
- Web host configuration and SSL
- View components invoked as tag helpers
- Configuration and logging
- Using Razor Pages