A Full-Stack Web App Using Blazor WebAssembly and GraphQL—Part 7 | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (163).NET Core  (29).NET MAUI  (81)Angular  (81)ASP.NET  (50)ASP.NET Core  (79)ASP.NET MVC  (88)Azure  (38)Blazor  (160)DocIO  (23)Essential JS 2  (89)Essential Studio  (180)File Formats  (33)Flutter  (123)JavaScript  (190)Microsoft  (114)PDF  (68)React  (65)Succinctly series  (128)Syncfusion  (634)TypeScript  (32)Uno Platform  (3)UWP  (4)Vue  (40)Webinar  (35)Windows Forms  (59)WinUI  (56)WPF  (140)Xamarin  (157)XlsIO  (26)Other CategoriesBarcode  (5)BI  (29)Bold BI  (5)Build conference  (6)Business intelligence  (54)Button  (4)C#  (121)Chart  (59)Cloud  (13)Company  (445)Dashboard  (8)Data Science  (3)Data Validation  (6)DataGrid  (56)Development  (418)Doc  (7)DockingManager  (1)eBook  (96)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (24)Extensions  (19)File Manager  (4)Gantt  (14)Gauge  (11)Git  (4)Grid  (28)HTML  (12)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (333)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (33)Performance  (10)PHP  (1)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (8)Road Map  (11)Scheduler  (39)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (23)Solution Services  (3)Spreadsheet  (11)SQL  (8)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (95)UI  (238)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (23)Visual Studio Code  (17)Web  (396)What's new  (229)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
A Full-Stack Web App Using Blazor WebAssembly and GraphQL—Part 7

A Full-Stack Web App Using Blazor WebAssembly and GraphQL—Part 7

In the previous article of this series, we learned how to implement client-side state management in our application. We also added a watchlist to it.

This article will show you how to deploy our MovieApp application to the IIS and Azure app services.

Publish Blazor server app in IIS

Configure the Windows machine for deployment

For this tutorial, I am using a Windows 11 system.

Enable IIS on Windows

Open the control panel on your Windows machine. Click Programs and Features. A new window will open. Click Turn Windows feature on or off under the menu on the left side. A new window called Windows feature will open.

Search for Internet Information Services (IIS). Expand the IIS option by clicking on the plus icon. You will find a list of sub-options under it. Select all the options under Web Management Tools & World Wide Web Services. Refer to the next image.

Turn Windows feature on or off
Click OK to install IIS.

Explore the best and most comprehensive Blazor UI components library in the market.

Install URL rewrite module

The URL rewrite module enables the site administrator to create customized rules to implement URLs that are easier for users to remember and are SEO-friendly, as well.

To learn more, please refer to the Microsoft documentation.

Navigate to URL Rewrite. Click Install this extension to download the URL rewrite module to your machine.

Refer to the following image.

Install URL RewriteInstall the downloaded package on your machine.

Install .NET Core hosting bundle

Navigate to .NET official site. Click on the latest stable version of .NET. We are using .NET 6.0 in our app, so we will click on that option.

Refer to the following image.

Install .NET Core hosting bundle
A new window will appear. In the Run apps – Runtime section, observe that the link to download the hosting bundle is provided corresponding to the Windows option. Refer to the following image.

Download and install the .NET Core hosting bundle for WindowsDownload and install the .NET Core hosting bundle for Windows.

Important Notes

  • Install the .NET Core hosting bundle after installing IIS.
  • Restart your machine after installing the .NET Core hosting bundle.

Syncfusion’s Blazor components suite is the expert’s choice for building modern web apps.

Publish the Blazor application

Once the configuration of the Windows machine is complete, let’s focus on publishing our Blazor application:

  1. Right-click the MovieApp.Server project and then click Publish.
  2. In the Publish window that appears, click the Folder link and then click Next.
  3. In the next window, provide the path of the folder where you want your application to be published and then click Finish.
  4. Finally, click Publish at the top. The process of building and publishing will start.

Refer to the following image to see all the steps in action.
Publishing Blazor application
If there are no errors, then the app will be published successfully in the folder path you have provided.

Next, let’s focus on configuring the IIS.

Configuring IIS

To open the IIS manager:

  1. Open the Control Panel from the start menu.
  2. In the category view of the Control Panel, open System and Security and select Administrative Tools.
  3. Here, you’ll find the Internet Information Service (IIS) Manager. Double-click on it to open it.

Right-click on Sites in the left pane and then select Add Website. An Add Website window will appear. Fill out the details:

  • Site name: Enter the site’s name as per your choice. We will use the name MovieApp for this demo.
  • Physical path: Provide the path of the folder where you have published the Blazor application.
  • Host name: Provide the URL to be used to access the application in the browser. We will use movieapp.com for this demo.

Click OK to create the website.

The next step is to configure the application pool. An application pool corresponding to our website is created automatically once we add a new website. The name of the application pool is the same as the site name we provided while creating the website.

Select the Application Pools link and double-click on the pool movieapp. A new edit application pool window will appear. Select No Managed Code from the .NET CLR version dropdown and then click OK.

Refer to the next image to see all the steps in action.

Configuring the application pool

Configure the DNS host

The final step is to configure the DNS host file of the machine.

Navigate to the C:\Windows\System32\drivers\etc folder on your machine. Open the hosts file using a text editor of your choice.

Add an entry for the website URL in this file corresponding to the localhost IP address. Refer to the following image.

Configuring DNS hostThis configuration is required to ensure that we can access our deployed website on the local machine.

Execution and troubleshooting

Open a browser and navigate to Movie App page. You can see a page similar to the one in the following screenshot.

Hosted application with missing imagesYou can see that the movie posters are not being displayed. Let’s understand why this is happening and how we can fix it.

In our app, we have used the same database for the deployed environment and development environment. While running the app after deployment, it will try to fetch the posterPath from the Movie table of the database and try to locate the posters in the Poster folder of the server. But the posters are not available where we have published our app. So, we need to add the images to the Poster folder to resolve the issue.

Open the Poster folder in MovieApp.Server project and copy all the images. Navigate to the folder where you have published the app. You can see that a Poster folder is already created. Paste the copied images here.

If you refresh the website, you will see the posters, as shown in the following image.

Blazor application with GraphQLWe have successfully deployed the app to IIS. Let’s learn how to deploy it to Azure App Service.

Publish Blazor server app in MS Azure

Please create an Azure subscription account.

Every property of the Syncfusion Blazor components is completely documented for easy use.

Create a SQL Server resource on the Azure portal

Now, create a SQL Server on Azure to handle our database operations. Open the Microsoft Azure portal.

Click Create a resource. On the next page, locate the SQL Database resource and click Create. Refer to the next image.

Creating SQL Server resource on the Azure portal
A new page with the title “Create SQL Database” will appear. On this page, you will be asked to furnish the details for your SQL database.

You can provide the details in the Basics tab:

  • Subscription: Select the subscription type for your Azure account from the drop-down.
  • Resource group: You can either select an existing resource group name from the dropdown or create a new resource group by clicking Create new.
  • Database name: Provide a unique name for the database. This database name must satisfy the following validation criteria.
    DataBase name conditions
  • Server: Click Create new to create a new server for the database. A new window will appear. Provide the details:
    • Server name: Provide a unique server name.
    • Location: Provide a location.
    • Authentication Method: Select an authentication method as per your requirement. For this app, we will use SQL authentication. Configure the Server admin login and password.
      Refer to the following image to understand the server configuration.
      SQL Database server configuration
  • Compute + storage: Click Configure database. In the next window, select the option you need from the service tier dropdown.

Click Next at the bottom until you reach the Review + create tab. Click Create at the bottom of this tab to create the SQL database.

Refer to the following image.

Create and configure SQL database

Update the connection string in the application

Once the database is created, navigate to the database resource page. We must allow access to this resource through the internet using a public IP address. This will allow us to connect to this database from our local machine.

Click Set Server Firewall at the top. Under the Public access tab, click Selected networks. Click Save at the bottom.

We also need other Azure resources, such as the Azure App Service, to access our database. Therefore, select Allow Azure services and resources to access this server at the bottom of the page in the Exceptions section. Once again, click Save at the bottom.

The next step is to fetch the connection string.

Click Connection strings in the Settings menu on the left side of the page. Select the ADO.NET tab and copy the connection string.

Refer to the following image.

Updating the connection string in the application
Open the appsettings.json file in your project and replace the existing connection string of the local database with the connection string of Azure SQL Server.

Refer to the following code.

"ConnectionStrings": {
    "DefaultConnection": "Server=tcp:moviedbserver.database.windows.net,1433;
        Initial Catalog=MovieDB;Persist Security Info=False;
        User ID={YourUserID};Password={YourPassword};MultipleActiveResultsSets=False;Encrypt=True;
        TrustServerCertificate=Falst;Connnection Timeout=30;"
}

Explore the different application UIs developed using Syncfusion Blazor components.

Creating database objects

The Azure SQL database does not contain the tables that we are using in our app. We will create them using SSMS from our machine.

Open SSMS and connect to the Azure SQL Server by furnishing the following information:

  • Server name: Provide the server name as given in the connection string.
  • Authentication: Select SQL Server Authentication.
  • Login: Provide the user ID for the server.
  • Password: Provide the password for the server.

Refer to the following image.

Connect to SQL Server
Click Connect.

When you are trying to connect to the Azure SQL Server from your local machine, it will ask you to set up a firewall rule. Log in with the credentials of your Azure account. Select Add my client IP address and click OK.

Refer to the following image.

Creating new Firewall rule
Once the connection is made, create all the required tables in the database. You can get the SQL scripts for creating the tables from the Set up the database section of Part 1 of this series. Run these scripts to generate the tables.

Now, run the application from Visual Studio. You will be able to see the following screen.
Movie app with no data to display
Since the tables are empty, there is no movie data to display. However, you can see the genre data.

Publish the Blazor application to Azure

Right-click the MovieApp.Server project and click Publish. A Publish window will open asking you to select a target to publish. Select Azure and click Next.

You will be asked to connect to the Azure account from Visual Studio. Once the login is successful, it will ask you to select the Azure service to host the application. Select Azure App Service (Windows) and click Next.

The next window will list all the app services you have in your account. We will create a new app service instance for this app. Click Create New.

A new window will appear requesting you to provide the app service details. Provide a unique name for your app service. The name of the app service must be universally unique and should not be used by anybody else. Select the subscription name and resource group as per your account configuration. You can select an existing hosting plan or create a new one.

Refer to the following image.

Windows App Service

Click Create to create the Azure App Service instance. Select the newly created app service name and click Finish.

On the next page, you can verify all the information you have provided and then click Publish at the top. The process of building and publishing will start. After the publication is successful, the URL will launch in your machine’s default browser.

The website URL will be <app service name>.azurewebsites.net. You can see the webpage looks like the following image.

Published Blazor app
Currently, there is no data displayed since the DB tables are empty. Log in as the admin user and add some movie data. You can validate that the application is working as expected.

The application we have created in this series of articles is available at here.

See how Syncfusion Blazor components can be transformed into beautiful and efficient applications.

Upload the default poster image to the Azure App Service

We need to add the default poster image to the Azure App Service. This will ensure that the default poster image is displayed if the user fails to upload a poster for a movie.

We will upload the required file via the Kudu console.

Note: To learn more about the Kudu console, please refer to the Microsoft documentation
. Open the URL https://<app service name>. scm.azurewebsites.net to open the Kudu console corresponding to your app service.

Select Debug console -> PowerShell from the menu bar at the top. It will list the file system of our app service. Navigate to Site -> wwwroot -> Poster folder. Drag the default poster image to this path. The file is uploaded and will be available for the app service to consume.

Refer to the following image.

Uploading data to the Azure app service

GitHub reference

The complete source code of this application is available on GitHub.

Summary

Thanks for reading! In this article, we learned to configure IIS on a Windows machine and deploy our Blazor application on it. We learned about deploying and publishing a Blazor application on Azure. We created a SQL Server database on Azure and configured it to use as the database provider for our application. We finally deployed the Blazor application on the Azure App Service.

This article concludes the series on Blazor and GraphQL.

Syncfusion’s Blazor component suite offers over 70 UI components. They work with both server-side and client-side (WebAssembly) hosting models seamlessly. Use them to build marvelous apps!

If you have any questions or comments, you can contact us through our support forumssupport portal, or feedback portal. We are always happy to assist you!

Related blogs

Tags:

Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed
Scroll To Top