ASP.NET is Microsoft’s framework for building websites, web applications and web APIs. You write the code in C#, a popular, modern programming language, and ASP.NET supplies the tools for handling requests, showing pages, working with data and keeping users signed in. This guide explains what ASP.NET is, how it relates to C#, what you can build with it, and how to get started.
ASP.NET and C#: how they fit together
The two names are often mixed up, so it helps to separate them. C# is the programming language. ASP.NET is a web framework that runs on the .NET platform. C# is the most common language used with ASP.NET, so learning one naturally leads to the other. You learn C# for the language itself, then ASP.NET to use it for the web.
A simple way to think about it: C# is the language you write in, .NET is the platform that runs your code, and ASP.NET is the part of .NET that deals with the web.
ASP.NET vs ASP.NET Core
You will see both names, and they refer to different generations of the framework.
- ASP.NET (classic) is the older version built on the Windows-only .NET Framework. It includes Web Forms, MVC and Web API. Many existing business applications still run on it.
- ASP.NET Core is the newer, rewritten version. It is open source, cross-platform and designed to be fast and modular. It runs on Windows, Linux and macOS.
If you are starting from scratch, ASP.NET Core is the version to learn. Classic ASP.NET knowledge is mainly useful if you need to maintain an older system.
What you can build with ASP.NET
ASP.NET covers several kinds of web projects:
- Websites and web apps with server-rendered pages, using Razor Pages or MVC.
- Web APIs that return data (usually JSON) to mobile apps, single-page apps or other services.
- Interactive web interfaces written in C# with Blazor, instead of JavaScript.
- Real-time features such as live chat or notifications, using SignalR.
- Back-end services for internal tools, dashboards and business systems.
The main programming models
Razor Pages
Razor Pages ties each page to its own C# code. It is a good starting point because the structure is simple: one page, one file for the markup and one for the logic. It suits forms, content sites and straightforward apps.
MVC (Model-View-Controller)
MVC splits an app into three parts. Models describe the data, views produce the HTML, and controllers handle incoming requests and decide what to return. This separation helps keep larger projects organized and easier to test.
Web API and minimal APIs
When you need to deliver data rather than pages, you can use controller-based Web API or the lighter minimal API style, which lets you define endpoints in just a few lines of code.
Blazor
Blazor lets you build interactive user interfaces with C# and HTML. It is worth a look if you already know C# and would rather not write much JavaScript.
What you need to get started
You do not need expensive software to begin. The basics are:
- The .NET SDK, which is free from Microsoft and includes the compiler and command-line tools.
- A code editor. Visual Studio offers the most complete experience on Windows, while Visual Studio Code is a lightweight option that works on all major systems.
- A web browser for testing your app.
Create your first ASP.NET Core app
After installing the SDK, you can create and run a simple web app from the command line:
- Open a terminal and move to the folder where you want your project.
- Run dotnet new webapp -o MyFirstApp to create a Razor Pages project.
- Move into the new folder with cd MyFirstApp.
- Run dotnet run to start the app.
- Open the local address shown in the terminal in your browser to see the site.
From there, try editing a page in the Pages folder, save it and reload the browser to see the change. Small experiments like this are the quickest way to learn how requests, pages and code connect.
Working with data
Most real apps store information in a database. ASP.NET Core usually works with Entity Framework Core, an object-relational mapper that lets you read and write database records using C# classes instead of writing every SQL query by hand. It supports several database systems, including SQL Server, PostgreSQL and SQLite. SQLite is a handy choice while you are learning because it needs no separate server.
Built-in features worth knowing
- Dependency injection to manage the services your app uses.
- Configuration through settings files and environment variables.
- Authentication and authorization to control who can sign in and what they can access.
- Middleware to handle logging, error pages, security headers and more as requests pass through your app.
- Hosting options that let you run your app on your own server, in containers or on a cloud platform.
A sensible learning path
- Learn the C# basics: variables, conditions, loops, classes and collections.
- Build a small Razor Pages site with a form.
- Add a database with Entity Framework Core.
- Create a simple Web API and call it from a browser or another app.
- Add user accounts and learn the basics of web security.
- Deploy a project so you understand how an app runs outside your own computer.
Building a small project at each step, such as a to-do list, a notes app or a simple blog, will teach you more than reading alone.
Frequently asked questions
Is ASP.NET a programming language?
No. ASP.NET is a web framework. The language you normally use with it is C#, though F# and Visual Basic are also supported on the .NET platform.
Is ASP.NET free?
Yes. ASP.NET Core and the .NET SDK are free and open source. Visual Studio has a free Community edition for individuals and some other uses, and Visual Studio Code is free as well. Check the license terms if you plan to use it in a company.
Do I need Windows to use ASP.NET?
Not for ASP.NET Core, which runs on Windows, Linux and macOS. Classic ASP.NET on the .NET Framework is limited to Windows.
Should I learn C# before ASP.NET?
Yes, at least the basics. Knowing how classes, methods and collections work will make ASP.NET far easier to follow, since nearly everything in the framework is written in C#.