How to publish a Blazor Server Application to IIS

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

1. 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

2. 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

3. 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

4. Publish the Application using the “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 Blazor Server Application Artifacts

5. Host the application in IIS

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

1. Copy the published folder to webroot 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

3. 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

6. 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: Top 7 Visual Studio 2019 extensions for Web Projects |  The difference in Blazor Server and WebAssembly Application |  Exploring Blazor WebAssembly App Project Structure |  Top 10 Productivity Tips and Tricks in Visual Studio 2019 |  CRUD Operations in WPF using EntityFrameworkCore and SQLite |  How to implement Dependency Injection in WPF |  How to use External Tool in Visual Studio 2019 |  Top Features of Visual Studio 2019 Community Edition |  Basic CRUD operations in Blazor using SQLite as the database |  How to consume REST API in Blazor Application |  Blazor Lifecycle Methods |  A Simple way to Call Javascript in Blazor Application   ]  

5 1 vote
Article Rating
Subscribe
Notify of
guest
3 Comments
oldest
newest most voted
Inline Feedbacks
View all comments
3
0
Would love your thoughts, please comment.x
()
x