When you start in the world of ASP.NET, one of the first things you will encounter is that there are different types of projects that we can choose from, depending on our needs.
In fact, it is one of the most confusing things at first because there are a huge number of options, and it’s easy to get lost among so many choices.
So let’s take a look at the main projects in ASP.NET, their features, and when it is most appropriate to use each one.
Here is a summary of the different types of ASP.NET projects that you will encounter.
Command | Project Type | Description |
---|---|---|
dotnet new web | Empty | Creates an empty project |
dotnet new webapi | ✅ RESTful API | Creates an API that follows RESTful style for web services |
dotnet new mvc | ❌ MVC | Creates an application with the Model-View-Controller pattern |
dotnet new razor | ❌ Razor Pages | Creates a project with Razor Pages |
dotnet new blazorwasm | Blazor WebAssembly | Creates a Blazor client application with WebAssembly. |
dotnet new blazorserver | Blazor Server | Creates a Blazor Server application |
Not all are equally useful, nor used (not even remotely), and some of them are maintained for compatibility. Currently, the ones you will use most frequently are:
- ✅ RESTful API: For almost everything
- Blazor: If you want to develop in this technology
- Empty Project: For a quick test (or to start from scratch)
But if you want more information about all of them, here it is so you can get to know them and know when it’s appropriate to use them (or not) 👇
Creates an empty project without any predefined structure. This is useful if you want to create a completely custom application or if you need full control over the project configuration.
To create an empty project, simply run:
dotnet new web -n MyEmptyProject
This will generate an empty project where you can add what you need: controllers, views, static files, services, among others.
Generates a RESTful API that follows HTTP conventions, using JSON as the data interchange format.
This type of project is common for exposing backend services, where a graphical interface is not necessary, but endpoints are provided that can be consumed by frontend or mobile applications.
To create an API project, use the following command:
dotnet new webapi -n MyApi
When to use it:
- Web Services: If you are developing a backend that will be consumed by different clients.
- Microservices: If you are building a microservices architecture, each service can be a RESTful API.
- SPA Applications: APIs + SPA frontends (React, Angular, Blazor).
Creates a project based on the Model-View-Controller (MVC) pattern. This pattern divides the application into three main components:
- Model (Model): Represents the data and business logic.
- View (View): Represents the graphical interface of the application.
- Controller (Controller): Acts as an intermediary between the model and the view.
To create a new MVC application, open the console and run the following command:
dotnet new mvc -n MyApplicationName
When to use it:
- It has been the classic for years.
- Nowadays, it is not used as much except in existing applications (legacy)
Razor Pages was released with .NET Core 2.0 (2017), promoted by Microsoft as a simpler alternative to MVC. Unlike MVC, a strict separation of controllers and views is not required.
However, it did not achieve great popularity, except in internal projects, administrative forms, or environments where something very simple is sought without using SPA (React, Angular, Blazor).
To create a project with Razor Pages, run:
dotnet new razor -n MyRazorPageApp
When to use it:
- ⛔If you are threatened with a gun and have no other choice… (and even then I would consider it)
Blazor is a web application development framework that allows you to create interactive applications using C# instead of JavaScript.
Blazor can run on the server (Blazor Server) or on the client (Blazor WebAssembly).
dotnet new blazorserver -n MyBlazorApplication
This command will create a new Blazor Server project with the basic structure of folders and files needed.
When to use it:
- Interactive Applications: If you are developing a web application that requires high user interactivity.
- Single Page Applications (SPA): If you are building a single-page application (SPA) and prefer to use C# instead of JavaScript.
Common Use Cases
We have seen the types of projects that ASP.NET offers. These are the “real project types.” When we create a project we will have to choose a type and we cannot change it.
But do not confuse the “project type” of ASP.NET with what we can do with this project (use cases)
We have already seen that the most powerful and versatile project type is RESTful API. But this does not mean we can only create APIs with it.
So let’s look at the “use cases” that we can perform with ASP.NET, either alone or with other technologies 👇.
Development of RESTful APIs
The most obvious and popular use of ASP.NET is the creation of RESTful APIs.
These APIs are the foundation of most modern applications and allow communication between the frontend and the backend, or among different services.
Key features:
- Native support for JSON: ASP.NET Core makes it easy to serialize and deserialize objects to JSON, the standard format for REST APIs.
- Routing: Allows defining routes declaratively, simplifying the creation of endpoints.
- HTTP verb handling: Supports methods like GET, POST, PUT, DELETE, PATCH, among others.
Microservices
ASP.NET is an excellent choice for implementing microservices architectures, due to its lightweight nature and performance. This makes it ideal for independent services that communicate with each other.
Key features:
- Containers and Docker: ASP.NET Core integrates with Docker, facilitating the creation of images and managing containers.
- gRPC: Supports gRPC for efficient communication between services.
- Scalability: Designed to be scalable both horizontally and vertically.
Real-time Applications with SignalR
For applications that require real-time communication (such as chats or instant notifications), ASP.NET Core offers SignalR.
This library simplifies the implementation of real-time functionalities.
Key features:
- WebSockets: Utilizes WebSockets for bidirectional communication.
- Scalability: Supports multiple servers and simultaneous connections.
- Easy integration: Easily integrates with existing applications.
Mobile Applications with ASP.NET Backend
ASP.NET is also used as a backend for mobile applications, providing APIs that can be consumed by iOS, Android, or cross-platform applications (such as Xamarin or Flutter).
Key features:
- JWT Authentication: Supports JSON Web Tokens for secure authentication.
- Scalability: Designed to handle large volumes of requests.
- Cross-platform compatibility: Works on Windows, Linux, and macOS.
Single Page Applications (SPA)
ASP.NET is compatible with frontend frameworks like React, Angular, and Vue.js, making it an excellent choice for building single page applications (SPA).
Key features:
- Frontend integration: Supports the creation of SPA projects with preconfigured templates.
- Optimized performance: Designed to offer high performance in SPA applications.
- Full-stack development: Allows developers to work on both the frontend and backend.