How to publish a Blazor Server Application to IIS

How to publish a Blazor Server Application to IIS 1

In this blog post, we will discuss how to publish a Blazor Server Application to IIS. Here are we going to create a Blazor Server application using the default Blazor Server template in Visual Studio 2019 and we will publish the same in the IIS server. If you are completely new to Blazor application, I would highly recommend you to check the introductory post.

Blazor is a new framework provided by Microsoft to build interactive client-side web applications using C# programming language and Razor syntax on top of the .NET Core framework. The beauty of this framework is that the developer need not know any JavaScript and can leverage the existing .NET, .NET Core frameworks, and its associated NuGet packages to power the Blazor application. The developer can build a Blazor application that can run on the server or directly inside the client browsers.

Prerequisite:

Step to publish a Blazor Server application to IIS

  1. Enable the Internet Information Service (IIS) feature.
  2. Install ASP.NET Core Runtime Hosting Bundle.
  3. Create a Blazor Server Application in Visual Studio 2019.
  4. Publish the Application to a “Folder or File share” profile.
  5. Host the application in IIS.
  6. Browse the application.

Enable the Internet Information Service (IIS) feature

The first step is to have Internet Information Services (IIS Web Server) up and running so the application can be hosted in it. The step can be skipped if the IIS is already up and running else the following step needs to be performed.

1. Open Program and Features Dialog

  • Press Windows Key + R and type appwiz.cpl and press OK to open the dialog.
publish a Blazor Server Application to IIS appwiz.cpl
Publish a Blazor Server Application to IIS – Open Program and Features

2. Select “Turn Windows feature on or off”

Publish a Blazor Server Application to IIS
Turn Windows features on or off

3. Select Internet Information Service and enable the following

  • Web Management Tools
  • World Wide Web Services
Publish a Blazor Server Application to IIS - enable IIS features
Publish a Blazor Server Application to IIS – Enable IIS features

Enabling the feature might require to restart the machine, so restart the machine.

Publish a Blazor Server Application to IIS - Reboot
Publish a Blazor Server Application to IIS – Reboot

Install ASP.NET Core Runtime Hosting Bundle

The second step is to install the ASP.NET Core Runtime Hosting Bundle. The Blazor Server is executed as an ASP.NET Core application on the server, so the runtime requirement is the same as an ASP.NET Core application.

The Runtime Hosting Bundle will install the IIS runtime support (ASP.NET Core Modules) so that we can host the Blazor Server application on the IIS. The installer can be found on the .NET Core download page here: and can be found under the “Run apps – Runtime” section of the page as shown in the snapshot.

Publish a Blazor Server Application to IIS - Hosting Bundle Download
Publish a Blazor Server Application to IIS – Hosting Bundle Download

Download and install the package. Completing this step will make the IIS ready to host the Blazor Server application.

Publish a Blazor Server Application to IIS - Install Hosting Bundle
Publish a Blazor Server Application to IIS – Install Hosting Bundle

Create a Blazor Server Application

The next step is to create a Blazor Server application, if you have an existing application then you can skip this step entirely. The application is created using the default Blazor Server project template and no code changes have been made to the application. The short video shows how to create a Blazor Server application in Visual Studio 2019.

Create a Blazor Server Application in Visual Studio 2019

Publish the Application using “Folder or File share” profile.

Now we have the application ready, so we will publish it. Steps to publish the application to a local folder:

  • Right-click on the project name and select Publish.
  • Select Folder from “Pick a publish target” and click on “Create Profile
  • Click Publish
  • Make a note of the published location from the Output Window

The entire step is shown in the GIF below.

Publish a Blazor Server Application to IIS - Publish Artifacts
Publish Blazor Server Application Artifacts

Host the application in IIS

At this point we have out published artifacts ready, the next step is to host these artifacts in IIS.

1. Copy the published folder to web root folder C:\inetpub\wwwroot\

Publish a Blazor Server Application to IIS - Copy Artifacts to web root folder
Copy Artifacts to IIS Web Root folder

2. Open IIS Manager

Press Windows + R, and type inetmgr and press OK.

Publish a Blazor Server Application to IIS - Open IIS
Open IIS Manager

2. Add Website

Right click on Sites and select Add Website

Publish a Blazor Server Application to IIS - Add Website
Add Website

Provide the following details in Add Website dialog

  1. Site name: HelloBlazor [put your own name]
  2. Physical path: C:\inetpub\wwwroot\publish\
  3. Port: 8090 [put your own name]
  4. Click OK
Publish a Blazor Server Application to IIS - Website details
Website details

Browse the application

Open the browser and put the URL: localhost:8090 (your given port number)

Publish a Blazor Server Application to IIS - Browse Application
Browse application

This concludes the post, I hope you find the post on how to publish a Blazor Server Application to IIS helpful. Thanks for visiting, Cheers!!!.

[ Further readings: The difference between Blazor Server and WebAssembly App   | Exploring Blazor WebAssembly App Project Structure |  How to consume REST API in Blazor Application |  How to call JavaScript in Blazor Application  |  Blazor Application Lifecycle methods  |  Top 5 Blazor Component Libraries  |  Creational Design Patterns  |  Builder Design Pattern in C#  |  Microsoft .NET Framework Version History  |  Important Global Visual Studio 2019 Shortcuts ]

0 0 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments