In this article, we will understand how to deploy an ASP.NET Core hosted Blazor application with the help of IIS 10 on a Windows 10 machine. We will be using Visual Studio 2017 to publish the app and SQL Server 2014 to handle DB operations. We will also troubleshoot some of the common hosting issues for a Blazor application.
Please refer to my previous article Cascading DropDownList in Blazor Using EF Core to create the application that we will be deploying in this tutorial.
Since we are going to deploy an ASP.NET Core hosted Blazor application, the first step is to install .NET Core hosting bundle in our machine.
Follow the below steps to download .NET Core hosting bundle:
Once the download is finished, double click to start installing it. You can see a window similar to the one shown below:
Important Note
Once .NET Core hosting bundle installation is successful and you have restarted your machine, open the Blazor application solution using VS 2017.
Right click on Server project of your solution and click publish. In this case it will be BlazorDDL.Server >> Publish
You will see a screen similar to below. Select Folder from left menu and provide a folder path. You can provide any folder path where you want to publish your app.
Click on publish. Visual Studio will start publishing your application. If there is no build errors then your application will be published successfully to the folder you have mentioned.
After the publishing is successful, we will move on to configure IIS.
Open IIS and right click on Sites >> Add Web Site.
An “Add Website” pop up box will open. Here we need to furnish details in three fields
Click on OK to create the website. Refer to the image below:
Next step is to configure the “Application Pool” for our site. The application pool name will be same as the “Site name” we have provided in last step. Therefore, in this case the application pool name will be “ankitsite”. Click to “Application Pools” from the left panel and double click on the pool “ankitsite”. It will open an “edit application pool” window. Select “No Managed Code” from the .NET CLR version dropdown. Refer to the image below:
Here is the whole process of configuring IIS explained in a gif image.
The last step is to configure our DNS host file.
Navigate to C:\Windows\System32\drivers\etc path in your machine and open the “hosts” file using any text editor.
We need to add the hostname that we provided in IIS against localhost IP address. Refer to the image below:
Hence, we have successfully hosted a Blazor application on IIS.
Open any browser on your machine and enter the hostname you have configured. You can see that the application will open in the browser window.
In this section, we will look into some of the common problems that you can face while hosting a Blazor application.
Check if the hostname is configured correctly in host file. Make sure that your machine is not connected to any VPN server. Also, if you are using any Web proxy then disable it.
This error message is clear. The publish folder is inaccessible because of insufficient permissions. Grant Read permission to the IIS_IUSRS group on the publish folder so that it can access Web.config file.
Make sure that your connection string is in correct format. The user id that you have specified in your connection string should have db_datareader and db_datawriter permissions. If the issue persists then provide the user with db_owner permission.
This issue generally appears when you try to do a PUT, POST or DELETE operation in your web API. To mitigate this issue we need to alter the IIS setup configuration.
Navigate to Control Panel >> Turn Windows feature on or off. Then navigate to Internet Information Services >> World Wide Web Services >> Common HTTP Features and uncheck the “WebDAV Publishing” option and click OK. Refer to the image below:
The cause of this error is that the client and the server of the application are not on the same port. The browser will restrict the application to make web API calls due to same-origin policy.
To resolve this issue you need to enable Cross-Origin Requests (CORS) in your application. Please refer to Microsoft documents on Enable Cross-Origin Requests (CORS) in ASP.NET Core.
In this article, we learned how to deploy a Blazor application on IIS in windows machine. We also learned how to resolve some of the common hosting issues while deploying a Blazor application.
Get my book Blazor Quick Start Guide to learn more about Blazor.
You can check my other articles on Blazor here
You can also find this article at C# Corner.
Introduction Blazor is a .NET web framework that allows us to create client-side applications using…
Introduction In this article, we are going to create a sudoku solver with the help…
Introduction In this article, we will learn how to implement Azure serverless with Blazor web…
Introduction Angular is an open-source framework that allows us to create applications for multiple platforms…
Introduction In this article, we will create an optical character recognition (OCR) application using Angular…
Introduction In this article, we will create an optical character recognition (OCR) application using Blazor…
View Comments
Thanks for a very detailed post :-)
How can we do this with AWS Beanstalk? Please help, I have my application and have attempted to use the AWS Tool for Visual Studio, but I think something is wrong because I get a Method Not Allowed error.
Thanks. Got it working for Me - even in 2020!