Search⌘ K
AI Features

Blazor Server

Explore the Blazor Server project template, its hosting model, and key components like Program.cs setup, Pages and Shared folders, and Razor Pages. Understand how to configure middleware and structure your application for server-side Blazor apps.

The Blazor Server has a different hosting model from Blazor WebAssembly. Therefore, its application project structure is also different. We have an example of a Blazor Server project template in the code widget below.

<Router AppAssembly="@typeof(App).Assembly">
    <Found Context="routeData">
        <RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
        <FocusOnNavigate RouteData="@routeData" Selector="h1" />
    </Found>
    <NotFound>
        <PageTitle>Not found</PageTitle>
        <LayoutView Layout="@typeof(MainLayout)">
            <p role="alert">Sorry, there's nothing at this address.</p>
        </LayoutView>
    </NotFound>
</Router>
Blazor Server project setup

Project file and dependencies

In the setup above, we have a project called Blazor. The structure of the Blazor.csproj file is as follows:

XML
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
</Project>

As we can see, a Blazor Server project doesn’t rely on additional dependencies. It is just a typical ASP.NET Core application. We are only using inbuilt components of ASP.NET Core. ...