ASP.NET Tutorial menu

ASP.NET Introduction

ASP.NET Core is a framework for building web applications and APIs with C#.

What is ASP.NET Core?

  • It is made by Microsoft and is free and open source
  • It runs on Windows, macOS and Linux
  • You write the server code in C#
  • It can build normal websites, web APIs, and real-time apps
  • It is part of the .NET platform

ASP.NET vs ASP.NET Core

Old ASP.NET (Framework)ASP.NET Core
Runs onWindows onlyWindows, macOS, Linux
Released20022016
SpeedGoodVery fast
StatusOnly maintainedActively developed
Use for new projectsNoYes

When people say "ASP.NET" today, they usually mean ASP.NET Core. This tutorial teaches only the modern version.

Ways to Build Pages

ASP.NET Core gives you several styles. You will learn the two most useful for beginners:

  • Razor Pages: each page is a .cshtml file with its own C# code. Great for websites and forms.
  • Minimal APIs: small C# functions that answer URLs, usually with JSON. Great for mobile app back-ends.

There is also MVC (Models, Views, Controllers) for large apps, and Blazor for interactive pages written in C#.

Installing .NET

  1. Download the .NET SDK (version 8 or newer) from the official dotnet website.
  2. Install it like any other program.
  3. Open a terminal (Command Prompt, PowerShell or Terminal) and check it:

Example

bash
dotnet --version
Output
8.0.400

Your version number may be different. For an editor, use Visual Studio (Windows) or VS Code with the C# Dev Kit extension.

Creating Your First App

Example

bash
dotnet new web -o HelloApp
cd HelloApp
dotnet run
Output
Building...
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5123
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.

Open the address shown (the port number will differ) in your browser, and you will see the text "Hello World!".

CommandWhat it does
dotnet new webCreates an empty web app
dotnet new webappCreates a Razor Pages app
dotnet new webapiCreates a web API project
dotnet runBuilds and starts the app
dotnet watchRuns the app and reloads it when you save a file

Use dotnet watch while learning. Every time you save, the browser updates and you see your change at once.

Changing the Message

Open Program.cs and change the text:

Example

csharp
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/", () => "Welcome to Workownix, Karachi!");
app.MapGet("/about", () => "We teach IT courses in Orangi Town.");

app.Run();

Now / shows the first message and /about shows the second:

Output
Welcome to Workownix, Karachi!

Exercise

Exercise

Which command creates a new Razor Pages project?

Learn ASP.NET with a teacher

Join the Full Stack Development course at Workownix, online or in Orangi Town, Karachi, and get a certificate.

See the course Ask on WhatsApp