9.2. Create a New ASP.NET Project

ASP.NET is a framework in the .NET Core family that is used to build web applications. While ASP.NET can be used to build a wide variety of web applications, we will be focusing on using it to build MVC web applications.

9.2.1. Getting Started

To create a new ASP.NET MVC project, start a new project in Visual Studio.

9.2.1.1. Windows Users

  1. Use the Get started Menu to Create a new project.

  2. When selecting the type of project, select ASP.NET Core Web App (Model-View-Controller).

    There are 2 ways to find this easily:
    1. Use the search bar.

    2. Select “Web” from the dropdown menu.

    Once you have your project type, click Next.

  3. Name your project HelloASPDotNET and put it in the appropriate directory for all of your classwork. Hit Next.

  4. Select the Framework. We are going to use .NET Core 6.0. You do not need to adjust any other options at this point. Select Create!

  5. Visual Studio creates a fully-functional web application for you.

Troubleshooting

This tutorial for Windows can help you if you are stuck.

9.2.1.2. Mac Users

  1. Open Visual Studio for Mac and select a New

  2. The type of project is a Web Application (Model-View-Controller). In the left-side menu, select App from under the Web and Console list. Continue on to the next screen.

  3. Target Framework will be .NET 6.0. You don’t need to adjust any other settings at this time.

  4. Name your project HelloASPDotNET and put it in the appropriate directory for all of your classwork. Hit Next.

  5. Visual Studio creates a fully-functional web application for you.

Troubleshooting

Microsoft created a tutorial for creating an MVC in Visual Studio, but for the Mac version they recommend the following guide.

Note

The guide is working with .NET 5.0 which is no longer supported. Make you that you are using .NET 6.0.

9.2.1.3. All Users

  1. Now launch the application!

    1. Mac Users: Click Run. It is a button that looks like a triangle pointing to the right.

    2. Windows Users: Try clicking IIS Express first. If this results in an HTTP Error 500.0, use the dropdown arrow next to IIS Express. Select HelloAspDotNet (or whatever you named your project) and try launching the application again.

  2. Eventually, your browser will open and display your application. Take note of the port number in the address bar.

Troubleshooting

Refer to the guides mentioned above

Note

The home page of your application already contains a link to a tutorial from Microsoft on how to use ASP.NET MVC. If you want extra study materials, check out that tutorial from the home page Microsoft designed!

9.2.2. Explore the Code

In the Controllers directory, check out HomeController.cs. Microsoft provided the code in HomeController and that is why our application ran immediately after we created it and was full of content. As we work on our new application, we will be adding a new controller, HelloController.

Note

As you code along with the videos, you will be working on your own project. However, should you want to review a step or double-check your code, fork LaunchCode’s HelloASPDotNETDemo repository to see what the code looked like at each stage. The repository is up on Github. The main branch contains the code after creation and also shows the starting point for the next chapter.

9.2.3. Check Your Understanding

Question

True/False: You should take note of the port number the server is using to run your application.

  1. True

  2. False