As mentioned in Part 1, in this post I will show how to create a new blazor server web app and some further basic information.

To build your first web app with Blazor server I would also recommend to read the following intro from Microsoft which I was also using first.

Blazor Tutorial – Build your first Blazor app

Create a new Blazor server web app

I will use here Visual Studio 2022 and filter for templates about C#, on Windows and for the Web. You can also see here the template for a Blazor WebAssembly App.

I will choose the Blazor Server App template.

Blazor Server was included as part of .NET 5.0.

As of today, .NET 7.0 is the latest version, I will use it for the new blazor server web app here.

To get the latest .NET version you can run the Visual Studio installer.

Select the .NET version you want to use, as mentioned, I will use .NET 7.0 for the new web app.

As I want to authenticate users in my web app by using the on-premise Active Directory, I will select here Windows, for Azure AD you can select Microsoft identity platform.

Finally click on Create.

Finally our blazor server template was created with a bunch of files and folders you can see below red marked. I will explain the separate files and folders below.

Blazor project structure

ASP.NET Core Blazor project structure

Under Dependencies you will find as used to several assemblies used by the project. Inside the Properties folder you will find a launchSettings.json file which will defines different profile settings for the local development environment.

The wwwroot folder will include all static files the web app needs like css files, JavaScript files and images.

The Data folder will include the C# classes used for the web app, by default two sample classes are included by the template named WeatherForecast.cs and WeatherForecastService.cs.

The Pages folder will include your web app pages which in Blazor terminology called routable compontents/pages. In Blazor server you didn’t really have separate web pages as it is a single-page application (SPA).

single-page application (SPA) is a web application or website that interacts with the user by dynamically rewriting the current web page with new data from the web server, instead of the default method of a web browser loading entire new pages. The goal is faster transitions that make the website feel more like a native app.


Razor components (.razor) can include page directives which will used by Blazor for page routing.

Routing is in Blazor the mechanism that matches classic URLs to Razor components/pages.

If a Razor component for example includes the following @page directive.

@page “/home”

Blazor will render this component and send it to the browser when the user enters the following URL in the browser.

https://<FQDN Web App>/home

Blazor also supports multiple routes for a component, so you can add two @page directives to the component and Blazor will render for both URLs the component and send it to the users browser.

@page “/home”
@page “/home2”

More about routing in Blazor you will find at the following website.

Blazor University – Routing

You will also find the _Host.cshtml file in the Pages folder which is the root page of the app implemented as a Razor page. When any page of the app is initially requested like for example the index.razor, this page is rendered and returned in the response.

In .NET 6 there is a _host.cshtml and _layout.cshtml where the _layout.cshtml is referenced in the _host.cshtml.

It seems that Microsoft changed this in .NET 7 back like before in .NET 3 and .NET 5 to just have a _Host.cshtml.

This page also loads all css and JavaScript files. Further it loads the _framework/blazor.server.js file which I described in Part I.

The Shared folder will include razor components without the @page directive. These are classic components which can be used by other components and mainly by components with the @page directive.

For example the navigation menu you will find here in form of a razor component NavMenu.razor which is included in the MainLayout.razor component which by itself is also homed in the Shared folder.

In an app created from a Blazor project template, the MainLayout component is the app’s default layout.


You can also use the @layout Razor directive to apply a layout to a routable Razor component that has an @page directive.


Directly in the root folder you will find the _Imports.razor, App.razor, appsettings.json and Program.cs file.

The App.razor file is the root component of the app that sets up client-side routing using the Router component. The Router component intercepts browser navigation and renders the page that matches the requested address.

The _Imports.razor file includes common Razor directives to include in the app’s components (.razor), such as @using directives for namespaces.

The appsettings.json file provides configuration settings for the app.

Finally the Program.cs file it the app’s entry point that sets up the ASP.NET Core host and contains the app’s startup logic, including service registrations and request processing pipeline configuration.


Start Debugging the web app

When you now start debugging the web app by pressing F5 you will see the following blazor app from the predefined default template.

I will use later this ready to use web app as foundation to build a complete new blazor web app with its own layout.

We will see this in the next upcoming posts and some nice features we can implement with Blazor.

In order to understand the basics about Blazor, I would also strongly recommend to watch the 11 episodes from Jeff Fritz on YouTube or Microsoft directly. On YouTube you get a better navigation through the separate episodes.

Jeff Fritz will introduce you here to Blazor and really great explains the basics.

What is Blazor [1 of 11] | Blazor for Beginners

Blazor Tutorial – Build your first Blazor app

In Part III I will show how to use a custom layout template for your new Blazor web app.

Blazor Server Series

Blazor Server – Basics Part 1

Blazor Server – Basics Part 2

Blazor Server – Basics Part 3 – Custom Layout

Blazor Server – Basics Part 4 – Program.cs File

Blazor Server – Basics Part 5 – Authentication and Authorization

Blazor Server – Basics Part 6 – Query the on-premise Active Directory

Blazor Server – Basics Part 7 – C# Events, Delegates and the EventCallback Class

Blazor Server – Basics Part 8 – JavaScript interoperability (JS interop)

Blazor Server – Basics Part 9 – Responsive Tags and Chips

Blazor Server – Basics Part 10 – MS SQL Server Access and Data Binding

Blazor Server – Basics Part 11 – Create a Native Blazor UI Toggle Switch Component

Blazor Server – Basics Part 12 – Create a Native Blazor UI Toggle Button Component


ASP.NET Core Blazor project structure

Blazor Tutorial – Build your first Blazor app

Blazor Tutorial – Build your first Blazor app –> Let Jeff walk you through building a full Blazor app from start to finish

What is Blazor [1 of 11] | Blazor for Beginners

Blazor University – Routing