Create an ASP.NET Core project from the Visual Studio C# templates.
- [Instructor] Please begin by opening up Visual Studio. Visual Studio comes with several project templates to get us started. Let's head over to File, New, Project. And make sure .NET Core is selected from Visual C#. Then let's select ASP.NET Core Web Application. If we try to create the project as is, we will see we only have access to .NET Core 1. Let's update that to Core 2.0.
To do that, we will need to download and install the .NET Core SDK. If we head over to microsoft.com/net/download/core, we'll have access to downloading the SDK. We can go over to the Windows 64 Installer, or if you are using Mac or Linux, the options are listed below. Please follow along with the installation steps.
Now if we restart Visual Studio, we should have that option. So back in File, New, Project, we'll select ASP.NET Core Web Application, we'll hit OK, and then the drop-down we should see Core 2.0. So let's hit Cancel, so that we can name our application. We will call it MessageBoardBackend. And then let's navigate to our project folder.
Then let's hit OK. Then from the drop-down on the top, we'll select Core 2.0. And we have several project template options. Let's select Web API. There isn't much setup that we need to do since we selected the Web API template. So let's just hit OK. Since everything is already set up for us, we should be able to just run our application by going over to Debug, Start Debugging, or just hitting this play button on the top.
So let's do that now. As you can see, it's launched a browser with our local host URL /api/values. And we're getting two values in an array. Let's take a look at where that's coming from. If we close the browser, it will automatically stop the debug. Let's go into our Controllers folder on the right. Here we can see there's an example, ValuesController, that the template created for us.
If we scroll down, we can see there is a Get function that returns a string array with two values. And the ValuesController is what we saw earlier in the browser. A Controller processes incoming HTTP requests and sends out HTTP responses. If we look down further, on line 21, we can see there is another Get function. This one returns a string as well, except it's not in an array.
But it also takes a parameter. Let's start debugging again to see how we can trigger that endpoint. So by default, the browser does an HTTP GET on the values controller. Now if we supply a parameter, such as 5, we can see it's triggering the other endpoint, and we're getting the string value. Even though we passed in a value into the Get function, this isn't actually searching a database since we don't have one at this point, and it's returning this dummy value on line 23.
So no matter what value we pass in, whether it's 5 or 10, it will always return this dummy value. Next, let's take a look at implementing a more meaningful controller to actually pass our message data.
- Setting up the app infrastructure
- Creating and configuring the Angular 2 project
- Displaying data in Angular
- Refining the layout
- Creating the ASP.NET Core project
- Creating a controller with ASP.NET Core
- Creating a nav bar
- Registering users
- Authorizing resources
Skill Level Intermediate
Q: This course was updated on 10/18/2017. What changed?
A: The following topics were updated: setting up the app infrastructure, displaying data in Angular 2, getting data from ASP.NET Core, creating a controller with ASP.NET Core, and authorizing resources.