In ASP.NET Core 10, which dotnet new template — web, webapi, webapiaot, mvc, webapp, blazor or grpc — fits which kind of application?
answer
- UI or no UI first
- webapp and razor: one template
- AddControllersWithViews vs AddRazorPages
- --auth Individual only on UI templates
- grpc: Grpc.AspNetCore + greet.proto
basics
~20 sPick by what the app serves: web for an empty app, webapi for JSON APIs, webapiaot for a Native AOT API, mvc or webapp for server-rendered pages, blazor for a Blazor Web App, and grpc for gRPC services.
solid answer
~40 sStart from what the app returns. `web` is the empty template: `CreateBuilder`, `Build`, one `MapGet("/")`, `Run`, no packages. `webapi` is the JSON API template (Minimal APIs by default, controllers with `--use-controllers`, built-in OpenAPI). `webapiaot` is a separate Minimal API template on `CreateSlimBuilder` with `PublishAot`. `mvc` gives controllers with views (`AddControllersWithViews`, the `{controller=Home}/{action=Index}/{id?}` route); `webapp`, also called `razor`, gives Razor Pages (`AddRazorPages`, `MapRazorPages`). `blazor` is the Blazor Web App. `grpc` references `Grpc.AspNetCore`, calls `AddGrpc()` and `MapGrpcService<GreeterService>()` and ships `greet.proto`. Authentication choices differ: only `mvc`, `webapp` and `blazor` offer `--auth Individual` (ASP.NET Core Identity on SQLite by default); `webapi` offers `IndividualB2C`, `SingleOrg` and `Windows`; `web`, `webapiaot` and `grpc` have no `--auth`.
code
bash · 2 linesdotnet new webapi --use-controllers --no-openapi -o Couriers.Lockers.Api
dotnet new webapp --auth Individual -o Couriers.Admingo deeper
Recall each short name and what it is for: web empty, webapi JSON, mvc controllers with views, webapp Razor Pages, blazor components, grpc RPC, webapiaot Native AOT.
Explain what each template registers in Program.cs, which ones take --auth with which choices, and why grpc pins Kestrel to HTTP/2.
Choose templates per project in a solution, knowing that a template only sets defaults, and spot when a requirement such as local accounts rules one out.
Weigh standardising one template across teams against per-project choices, and decide where UI and API live as the product grows.
## Decide by what the application returns ASP.NET Core ships one framework and several starting points. Every web template writes a `Microsoft.NET.Sdk.Web` project targeting `net10.0` with nullable reference types and implicit usings on; they differ in **which services `Program.cs` registers, which endpoints it maps, which packages it references and which files sit beside it**. Choosing a template is choosing those defaults, not choosing a different framework — an `mvc` app can add Minimal API endpoints later and a `webapi` app can add Razor Pages. | Short name | Template name | What it wires up | Fits | |---|---|---|---| | `web` | ASP.NET Core Empty | `CreateBuilder`, `Build`, `MapGet("/", () => "Hello World!")`, `Run`; no package references | Learning, tiny services, starting from nothing | | `webapi` | ASP.NET Core Web API | Minimal APIs (or controllers with `--use-controllers`), `AddOpenApi` / `MapOpenApi` | JSON HTTP APIs | | `webapiaot` | ASP.NET Core Web API (native AOT) | `CreateSlimBuilder`, a source-generated JSON context, `PublishAot` | APIs that must publish as Native AOT | | `mvc` | ASP.NET Core Web App (Model-View-Controller) | `AddControllersWithViews`, `MapControllerRoute` with the default route, Views, Bootstrap and jQuery under `wwwroot/lib` | Server-rendered sites organised by controller | | `webapp` / `razor` | ASP.NET Core Web App (Razor Pages) | `AddRazorPages`, `MapRazorPages` | Page-focused server-rendered sites, admin back offices | | `blazor` | Blazor Web App | `AddRazorComponents`, `MapRazorComponents<App>`, `--interactivity` | Component-based UI in C# | | `grpc` | ASP.NET Core gRPC Service | `Grpc.AspNetCore`, `AddGrpc()`, `MapGrpcService<GreeterService>()`, `Protos/greet.proto` | Service-to-service RPC over HTTP/2 | Two notes on the names. `webapp` and `razor` are **two short names for the same template**. And `blazor` is the only server-hosted Blazor template since .NET 8: the old Blazor Server template and the WebAssembly "ASP.NET Core hosted" option were removed, and `blazorwasm` remains for a standalone WebAssembly app. ## What the server-rendered templates add `mvc` and `webapp` share a production-shaped pipeline: outside Development they call `UseExceptionHandler` (`/Home/Error` or `/Error`) and `UseHsts()`, then `UseHttpsRedirection()`, `UseRouting()`, `UseAuthorization()` and `MapStaticAssets()`, with `.WithStaticAssets()` chained on the controller route or on `MapRazorPages()`. `MapStaticAssets` replaced `UseStaticFiles` in the .NET 9 templates. The `grpc` template also sets `Kestrel:EndpointDefaults:Protocols` to `Http2` in `appsettings.json`, because gRPC needs HTTP/2, and its `GET /` endpoint only explains that a gRPC client is required. Its `Grpc.AspNetCore` reference is pinned by the 10.0.12 templates at 2.64.0. ## Authentication choices differ per template The `--auth` option is not uniform, which is a favourite follow-up: - `mvc` and `webapp`: `None` (default), `Individual`, `IndividualB2C`, `SingleOrg`, `MultiOrg`, `Windows`. - `webapi`: `None`, `IndividualB2C`, `SingleOrg`, `Windows` — **no `Individual`**. - `blazor`: `None` or `Individual`. - `web`, `webapiaot`, `grpc`: no `--auth` option. `--auth Individual` is the local-accounts option. On `webapp` it adds `AddDbContext<ApplicationDbContext>` with `UseSqlite` (an `app.db` file) unless `--use-local-db` asks for SQL Server LocalDB, `AddDatabaseDeveloperPageExceptionFilter()`, and `AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)` with `AddEntityFrameworkStores`. It also references `Microsoft.AspNetCore.Identity.UI`, the EF Core SQLite provider and the EF Core tools, and gives the project a `UserSecretsId`. ## A worked choice A courier start-up needs two projects: 1. **The parcel-locker API** that lockers and the mobile app call: `dotnet new webapi --use-controllers --no-openapi -o Couriers.Lockers.Api`. JSON only, controllers because the team prefers them. 2. **The back-office admin site** where dispatchers manage lockers: `dotnet new webapp --auth Individual -o Couriers.Admin`. Page-per-screen fits Razor Pages, and `Individual` gives dispatcher log-ins backed by ASP.NET Core Identity. Choosing `mvc` for the admin site would also work; Razor Pages simply keeps each screen's handler next to its markup. Choosing `webapi --auth Individual` for the admin site would fail: that choice does not exist on `webapi`. ## Templates set defaults, not limits Every template produces the same kind of `WebApplication`, so the boundaries between them are soft: - an `mvc` project can call `AddRazorPages()` and `MapRazorPages()` and serve both styles side by side — the `mvc` template itself calls `MapRazorPages()` beside its controller route when `--auth Individual` brings in the Identity UI pages; - a `webapp` site can add `MapGet` endpoints for a few JSON calls instead of a second project; - a `webapi` project can switch on Razor Pages or Razor components later by registering their services and mapping them. What a template does decide is the **first shape every developer sees** — folder layout, the sample page or endpoint, the packages in the `.csproj`. That is why interviewers ask it: the answer shows whether a candidate knows what each style costs before writing code. | Signal in the requirements | Template that starts closest | |---|---| | Only JSON, consumed by other programs | `webapi` | | Must publish as Native AOT, small and fast to start | `webapiaot` | | Forms and server-rendered screens, one handler per screen | `webapp` | | Server-rendered site organised around controllers and shared views | `mvc` | | Rich interactive UI written in C# components | `blazor` | | Strongly typed service-to-service calls from a `.proto` contract | `grpc` |
- What database does dotnet new webapp --auth Individual use, and how do you change it?SQLite: the template adds `Microsoft.EntityFrameworkCore.Sqlite`, a `DefaultConnection` of `DataSource=app.db;Cache=Shared`, and `UseSqlite`. Passing `--use-local-db` switches the generated code to `UseSqlServer` against SQL Server LocalDB instead.
- Why does a project from the grpc template refuse plain HTTP/1.1 clients by default?Its `appsettings.json` sets `Kestrel:EndpointDefaults:Protocols` to `Http2`, so Kestrel's endpoints speak HTTP/2 only. gRPC requires HTTP/2, and the template's `GET /` answer just tells a browser to use a gRPC client.
- webapp and razor are two different templates for Razor Pages
- dotnet new webapi --auth Individual adds Identity local accounts to an API
- The blazor template is the Blazor Server template under a new name
- The mvc template still calls UseStaticFiles for its wwwroot files
- dotnet new web gives you controllers and an OpenAPI document
Assumes the ASP.NET Core 10.0 templates; since .NET 8 the blazor template is the Blazor Web App, and since .NET 9 mvc and webapp use MapStaticAssets.