Create an ASP.NET Core Application Part I

This post is part of a series:

If you haven’t started using ASP.NET Core for .NET development, now is a great time to get started. The tooling (Visual Studio and VS Code) has evolved to a point where it is easy to stand up a web site in a day. For example, check out this site I created in a single day: https://www.movemyeyes.com/

ASP.NET Core is a cross-platform, high-performance, open-source framework for building modern, cloud-based, Internet-connected applications. With ASP.NET Core, you can:

  • Build web apps and services
  • Use your favorite development tools on Windows, macOS, and Linux
  • Run on IIS, Docker, Apache, and a few other hosting options. Yes, this means your ASP.NET Core applications can run on Linux and macOS!

Let’s get started. I prefer Visual Studio 2019 for creating ASP.NET Core applications, but you can also use VS Code and Visual Studio 2017.

Open Visual Studio 2019 (hereafter VS) and go select “Create a new project.” Then select the ASP.NET Core Web Application template.

ASP.NET Core Template

Give your project a name and select the location of your code. Then select “Create”.

The next screen that comes up is important because this is where you choose how much ‘scaffolding’ VS will do while creating your project.

ASP.NET Core Web Application

If you are feeling brave, you can select “Empty” and try to build your web site from scratch. But I recommend starting with the “Web Application” template. If you haven’t done ASP.NET Core development, it will help to start with the Web Application template to see how a well-formed application is structured.

The first thing to notice is the absence of ASPX pages. Instead, you will use files with the extension of cshtml (located in the pages folder.)

ASP.NET Core Pages folder

With .Net Core development, web applications are created using Razor pages. Razor pages are similar to ASPX pages, in that you have pages that render with C# code on the server. Razor takes a different approach and allows you to include the C# directly in the page more simply. I think the syntax is more precise and more readable.

Take a look at the Error.cshtml page, and you can see an example of a Razor page with embedded C#.

ASP.NET Core Code

The above code shows how a C# variable is inserted into the page and rendered by the server before returning the resonse object to the browser. Each cshtml file has a code-behind file with the file extension of cshtml.cs. If we look at the code-behind for the error page, we can see how the public member of the class named “RequestID” is set.

ASP.NET Core code-behind

The other important folder in your new .NET Core web application is called ‘wwwroot’. This is where all of your client-side code is found.

To keep this post short, I will discuss the “wwwroot” folder in the part II of this post.

How Can We Help? Find out how Lone Peak Software can help you with Azure development.

%d bloggers like this:
search previous next tag category expand menu location phone mail time cart zoom edit close