---
title: "How to deploy Blazor WebAssembly to Netlify"
excerpt: "Now that you can run .NET web applications without server-side code, you can deploy these applications to various static site hosts, such as Netlify."
publishDate: "2021-02-07T00:00:00"
createDate: "2021-02-08T04:20:26.203"
updateDate: "2021-04-02T23:33:06.78"
category: "dotnet"
categoryName: ".NET"
tags: [".NET","ASP.NET",".NET Core","ASP.NET Core","Blazor","Blazor WebAssembly","Blazor WASM","Netlify"]
permalink: "/blog/dotnet/how-to-deploy-blazor-webassembly-to-netlify"
canonical: "/blog/dotnet/how-to-deploy-blazor-webassembly-to-netlify"
image: {"src":"/media/wb4cm3yc/blazor-netlify-long.png","focalPoint":{"left":0.5,"top":0.4993280071679235},"crops":[{"alias":"Banner","width":1120,"height":400,"coordinates":null}]}
imageAlt: "Title: How to deploy Blazor WASM to Netlify. Blazor logo pointing to the GitHub logo and the GitHub logo pointing to the Netlify logo."
imageBackgroundColor: "#fff"
thumbnailImage: {"src":"/media/2qddoewj/blazor-netlify-square.png","focalPoint":{"left":0.5,"top":0.5},"crops":[{"alias":"thumbnail","width":250,"height":250,"coordinates":null}]}
thumbnailImageAlt: "Blazor logo pointing to the GitHub logo and the GitHub logo pointing to the Netlify logo."
metaTitle: "How to deploy Blazor WebAssembly to Netlify"
metaDescription: "Now that you can run .NET web applications without server-side code, you can deploy these applications to various static site hosts, such as Netlify."
ogTitle: "How to deploy Blazor WebAssembly to Netlify"
ogDescription: "Now that you can run .NET web applications without server-side code, you can deploy these applications to various static site hosts, such as Netlify."
ogImage: {"src":"/media/utljieb3/blazor-netlify-social.png","focalPoint":{"left":0.5,"top":0.501507697190922},"crops":[{"alias":"OpenGraph","width":1200,"height":630,"coordinates":null}]}
ogImageAlt: "Title: How to deploy Blazor WASM to Netlify. Blazor logo pointing to the GitHub logo and the GitHub logo pointing to the Netlify logo."
relatedPostKeys: ["3fa142faee1a488c91f507627e8059bb","0d375026e40743fdadc9c3b841802a6a","b01d783c18284f05b29774abcd096471"]
noIndex: false
noFollow: false
sitemapExclude: false
source: {"nodeId":1418,"contentKey":"1220545262ab42c291420e12ca2e6025","sortOrder":81}
---

<p>With ASP.NET Blazor WebAssembly (WASM) you can create .NET web applications that run completely inside of the browser sandbox. The published output of a Blazor WASM project are <strong>static files</strong>. Now that you can run .NET web applications without server-side code, you can deploy these applications to various <strong>static site hosts, such as Netlify</strong>.</p>
<p>Here are some other tutorials if you're interested in hosting Blazor WASM on other static site hosts:</p>
<ul>
<li><a href="https://swimburger.net/blog/dotnet/how-to-deploy-aspnet-blazor-webassembly-to-azure-static-web-apps">Azure Static Web Apps using GitHub</a></li>
<li><a href="https://daveabrock.com/2021/04/01/static-web-apps-azure-pipelines">Azure Static Web Apps using Azure DevOps (by Dave Brock)</a></li>
<li><a href="/blog/dotnet/how-to-deploy-blazor-webassembly-to-aws-amplify" type="document" title="How to deploy Blazor WebAssembly to AWS Amplify">AWS Amplify</a></li>
<li><a href="/blog/dotnet/how-to-deploy-blazor-webassembly-to-cloudflare-pages" type="document" title="How to deploy Blazor WebAssembly to Cloudflare Pages" data-anchor="#">Cloudflare Pages</a></li>
<li><a href="/blog/dotnet/how-to-deploy-blazor-webassembly-to-digitalocean-app-platform" type="document" title="How to deploy Blazor WebAssembly to DigitalOcean App Platform">DigitalOcean App Platform</a></li>
<li><a href="/blog/dotnet/how-to-deploy-blazor-webassembly-to-heroku" type="document" title="How to deploy Blazor WebAssembly to Heroku">Heroku</a></li>
<li><a href="https://swimburger.net/blog/dotnet/how-to-deploy-aspnet-blazor-webassembly-to-github-pages">GitHub Pages</a><a href="/blog/dotnet/how-to-deploy-blazor-webassembly-to-aws-amplify" type="document" title="How to deploy Blazor WebAssembly to AWS Amplify"></a></li>
<li><a href="https://swimburger.net/blog/dotnet/how-to-deploy-blazor-webassembly-to-firebase-hosting">Firebase Hosting</a></li>
</ul>
<p>This walkthrough will show you how to deploy Blazor WASM to Netlify. Netlify is a very popular static site host, but on top of hosting static sites, Netlify offers a ton of free and paid features which gives it an edge over the competition.</p>
<p>This guide will walk you through these high-level steps:</p>
<ol>
<li>Create Blazor WebAssembly project</li>
<li>Commit the project to a Git repository</li>
<li>Create a new GitHub project and push the Git repository to GitHub</li>
<li>Create a new Netlify site</li>
<li>Rewrite all requests to index.html</li>
</ol>
<p><strong>Prerequisites</strong>:</p>
<ul>
<li>.NET CLI</li>
<li>Git</li>
<li>GitHub account</li>
<li>Netlify account</li>
</ul>
<p class="panel panel--info"><strong>You can find the <a href="https://github.com/Swimburger/BlazorWasmNetlify">source code for this guide on GitHub</a>.</strong></p>
<h2 id="create-aspnet-core-blazor-webassembly-project">Create Blazor WebAssembly project</h2>
<p>Run the following commands to create a new Blazor WASM project:</p>
<pre style="color:#000000;background:#ffffff;">mkdir <span style="color:#2a00ff; ">BlazorWasmNetlify</span>&#10;cd <span style="color:#2a00ff; ">BlazorWasmNetlify</span>&#10;dotnet <span style="color:#2a00ff; ">new</span> <span style="color:#2a00ff; ">blazorwasm</span>&#10;</pre>
<p>In this tutorial, the Blazor WASM project is purposely put into the <em>src</em> subfolder to keep source code separate from other assets.</p>
<p>To give your application a try, execute <code>dotnet run</code> and browse to the URL in the output (probably <a href="https://localhost:5001/">https://localhost:5001</a>):</p>
<pre style="color:#000000;background:#ffffff;">dotnet <span style="color:#2a00ff; ">run</span>&#10;<span style="color:#3f7f59; "># Building...</span>&#10;<span style="color:#3f7f59; "># info: Microsoft.Hosting.Lifetime[0]</span>&#10;<span style="color:#3f7f59; ">#       Now listening on: </span><span style="color:#3f3fbf; ">https://localhost:5001</span>&#10;<span style="color:#3f7f59; "># info: Microsoft.Hosting.Lifetime[0]</span>&#10;<span style="color:#3f7f59; ">#       Now listening on: </span><span style="color:#3f3fbf; ">http://localhost:5000</span>&#10;<span style="color:#3f7f59; "># info: Microsoft.Hosting.Lifetime[0]</span>&#10;<span style="color:#3f7f59; ">#       Application started. Press Ctrl+C to shut down.</span>&#10;<span style="color:#3f7f59; "># info: Microsoft.Hosting.Lifetime[0]</span>&#10;<span style="color:#3f7f59; ">#       Hosting environment: Development</span>&#10;<span style="color:#3f7f59; "># info: Microsoft.Hosting.Lifetime[0]</span>&#10;<span style="color:#3f7f59; ">#       Content root path: C:\Users\niels\source\repos\BlazorWasmNetlify</span>&#10;<span style="color:#3f7f59; "># info: Microsoft.Hosting.Lifetime[0]</span>&#10;<span style="color:#3f7f59; ">#       Application is shutting down...</span>&#10;</pre>
<p>Optional: You can use the <code>dotnet publish</code> command to publish the project and verify the output:</p>
<pre style="color:#000000;background:#ffffff;">dotnet <span style="color:#2a00ff; ">publish</span>&#10;<span style="color:#3f7f59; "># Microsoft (R) Build Engine version 16.8.0+126527ff1 for .NET</span>&#10;<span style="color:#3f7f59; "># Copyright (C) Microsoft Corporation. All rights reserved.</span>&#10;<span style="color:#3f7f59; "># </span>&#10;<span style="color:#3f7f59; ">#   Determining projects to restore...</span>&#10;<span style="color:#3f7f59; ">#   All projects are up-to-date for restore.</span>&#10;<span style="color:#3f7f59; ">#   BlazorWasmNetlify -&gt; C:\Users\niels\source\repos\BlazorWasmNetlify\bin\Debug\net5.0\BlazorWasmNetlify.dll</span>&#10;<span style="color:#3f7f59; ">#   BlazorWasmNetlify (Blazor output) -&gt; C:\Users\niels\source\repos\BlazorWasmNetlify\bin\Debug\net5.0\wwwroot  Optimizing assemblies for size, which may change the behavior of the app. Be sure to test after publishing. See: </span><span style="color:#3f3fbf; ">https://aka.ms/dotnet-illink</span>&#10;<span style="color:#3f7f59; ">#   Compressing Blazor WebAssembly publish artifacts. This may take a while...</span>&#10;<span style="color:#3f7f59; ">#   BlazorWasmNetlify -&gt; C:\Users\niels\source\repos\BlazorWasmNetlify\bin\Debug\net5.0\publish\</span>&#10;</pre>
<p>In the publish directory, you will find a web.config file and a wwwroot folder. The config file helps you host your application in IIS, but you don't need that file for static site hosts. <strong>Everything you need will be inside of the wwwroot folder. The wwwroot folder contains the index.html, CSS, JS, and DLL files necessary to run the Blazor application</strong>.</p>
<h2 id="push-blazor-project-to-github">Push Blazor project to GitHub</h2>
<p>For this walkthrough, your application source code must be inside of a GitHub repository.<br>First, you need to create a local Git repository and commit your source code to the repository using these commands:</p>
<pre style="color:#000000;background:#ffffff;"><span style="color:#3f7f59; "># add the gitignore file tailored for dotnet applications, this will ignore bin/obj and many other non-source code files</span>&#10;dotnet <span style="color:#2a00ff; ">new</span> <span style="color:#2a00ff; ">gitignore</span>&#10;<span style="color:#3f7f59; "># create the git repository</span>&#10;git <span style="color:#2a00ff; ">init</span>&#10;<span style="color:#3f7f59; "># track all files that are not ignore by .gitignore</span>&#10;git <span style="color:#2a00ff; ">add</span> <span style="color:#2a00ff; ">--all</span>&#10;<span style="color:#3f7f59; "># commit all changes to the repository</span>&#10;git <span style="color:#2a00ff; ">commit</span> -m <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">Initial commit</span><span style="color:#2a00ff; ">"</span>&#10;</pre>
<p>Create a new GitHub repository (<a rel="noopener" href="https://docs.github.com/en/github/getting-started-with-github/create-a-repo" target="_blank">instructions</a>) and copy the commands to "push an existing repository from the command line" from the empty GitHub repository page, here's what it should look like but with a different URL:</p>
<pre style="color:#000000;background:#ffffff;">git <span style="color:#2a00ff; ">remote</span> <span style="color:#2a00ff; ">add</span> <span style="color:#2a00ff; ">origin</span> <span style="color:#2a00ff; ">https://github.com/Swimburger/BlazorWasmNetlify.git</span>&#10;git <span style="color:#2a00ff; ">push</span> -u <span style="color:#2a00ff; ">origin</span> <span style="color:#2a00ff; ">main</span>&#10;</pre>
<h2 id="create-the-netlify-site">Create the Netlify site&nbsp;<a href="/blog/dotnet/how-to-deploy-blazor-webassembly-to-netlify#create-the-netlify-site" aria-label="Anchor for heading: Create the Netlify site">#</a></h2>
<p>Log into Netlify and click on the "New site from Git" button on your Team page:</p>
<picture>
  <img src="https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1120/media/kaegvkyh/team-homepage.png" srcset="https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=430/media/kaegvkyh/team-homepage.png 430w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=645/media/kaegvkyh/team-homepage.png 645w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=718/media/kaegvkyh/team-homepage.png 718w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=860/media/kaegvkyh/team-homepage.png 860w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1077/media/kaegvkyh/team-homepage.png 1077w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1120/media/kaegvkyh/team-homepage.png 1120w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1436/media/kaegvkyh/team-homepage.png 1436w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1680/media/kaegvkyh/team-homepage.png 1680w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=2240/media/kaegvkyh/team-homepage.png 2240w" sizes="(max-width: 480px) 430px, (max-width: 768px) 718px, 1120px" width="1120" height="514" alt="Screenshot of the Netlify team overview page with an arrow pointing to the &quot;New site from Git&quot; button." loading="lazy" decoding="async">
</picture>
<p>Click on the GitHub button. This will open a new window that will take you through giving Netlify permissions to your GitHub account. Give Netlify the necessary permissions and at least give Netlify access to the GitHub repository you just created.</p>
<picture>
  <img src="https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1120/media/y15bfwdo/create-new-site-step1.png" srcset="https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=430/media/y15bfwdo/create-new-site-step1.png 430w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=645/media/y15bfwdo/create-new-site-step1.png 645w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=718/media/y15bfwdo/create-new-site-step1.png 718w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=860/media/y15bfwdo/create-new-site-step1.png 860w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1077/media/y15bfwdo/create-new-site-step1.png 1077w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1120/media/y15bfwdo/create-new-site-step1.png 1120w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1436/media/y15bfwdo/create-new-site-step1.png 1436w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1680/media/y15bfwdo/create-new-site-step1.png 1680w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=2240/media/y15bfwdo/create-new-site-step1.png 2240w" sizes="(max-width: 480px) 430px, (max-width: 768px) 718px, 1120px" width="1120" height="567" alt="Step 1 of creating a Netlify site from Git: Connect to Git provider. Mouse clicks on the &quot;GitHub&quot; button." loading="lazy" decoding="async">
</picture>
<p>On the second step, search for your GitHub repository and select the repository.</p>
<picture>
  <img src="https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1120/media/olsk5nrm/create-new-site-step2.png" srcset="https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=430/media/olsk5nrm/create-new-site-step2.png 430w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=645/media/olsk5nrm/create-new-site-step2.png 645w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=718/media/olsk5nrm/create-new-site-step2.png 718w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=860/media/olsk5nrm/create-new-site-step2.png 860w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1077/media/olsk5nrm/create-new-site-step2.png 1077w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1120/media/olsk5nrm/create-new-site-step2.png 1120w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1436/media/olsk5nrm/create-new-site-step2.png 1436w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1680/media/olsk5nrm/create-new-site-step2.png 1680w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=2240/media/olsk5nrm/create-new-site-step2.png 2240w" sizes="(max-width: 480px) 430px, (max-width: 768px) 718px, 1120px" width="1120" height="618" alt="Step 2 of creating a Netlify site from Git: Pick a repository. Mouse pointer clicks on a GitHub repository." loading="lazy" decoding="async">
</picture>
<p>In step 3 you need to provide the build command and where the published files can be found. <strong>Netlify's build agent has all the required .NET tooling installed on their Ubuntu build machines</strong>. </p>
<p>In the "<strong>Build command</strong>" field enter <code>dotnet publish -c Release -o release</code>. The c-argument tells the CLI to build in Release configuration. The o-argument tells the CLI to put the output in the release folder.<br>In the "<strong>Publish directory</strong>" field enter '<em><strong>release/wwwroot</strong></em>'. Finally, click the "Deploy site" button.</p>
<picture>
  <img src="https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1120/media/0rdjysfz/create-new-site-step3.png" srcset="https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=430/media/0rdjysfz/create-new-site-step3.png 430w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=645/media/0rdjysfz/create-new-site-step3.png 645w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=718/media/0rdjysfz/create-new-site-step3.png 718w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=860/media/0rdjysfz/create-new-site-step3.png 860w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1077/media/0rdjysfz/create-new-site-step3.png 1077w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1120/media/0rdjysfz/create-new-site-step3.png 1120w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1436/media/0rdjysfz/create-new-site-step3.png 1436w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1680/media/0rdjysfz/create-new-site-step3.png 1680w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=2240/media/0rdjysfz/create-new-site-step3.png 2240w" sizes="(max-width: 480px) 430px, (max-width: 768px) 718px, 1120px" width="1120" height="839" alt="Step 3 of creating a Netlify site using Git: Build options and deploy!" loading="lazy" decoding="async">
</picture>
<p>Netlify will create the site and you will be redirected to the site overview page. On this page, you can see the deploy status change in real-time.</p>
<picture>
  <img src="https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1120/media/vu5obvqd/deploy-in-progress.png" srcset="https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=430/media/vu5obvqd/deploy-in-progress.png 430w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=645/media/vu5obvqd/deploy-in-progress.png 645w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=718/media/vu5obvqd/deploy-in-progress.png 718w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=860/media/vu5obvqd/deploy-in-progress.png 860w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1077/media/vu5obvqd/deploy-in-progress.png 1077w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1120/media/vu5obvqd/deploy-in-progress.png 1120w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1436/media/vu5obvqd/deploy-in-progress.png 1436w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1680/media/vu5obvqd/deploy-in-progress.png 1680w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=2240/media/vu5obvqd/deploy-in-progress.png 2240w" sizes="(max-width: 480px) 430px, (max-width: 768px) 718px, 1120px" width="1120" height="736" alt="Netlify's Site overview page" loading="lazy" decoding="async">
</picture>
<p>When you click on the deploy under the "Production deploys" section, you will navigate the details of the deployment. Here you can see the log output in real-time of your deployment.</p>
<picture>
  <img src="https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1120/media/2ngg1ufd/deploy-in-progress-log.png" srcset="https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=430/media/2ngg1ufd/deploy-in-progress-log.png 430w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=645/media/2ngg1ufd/deploy-in-progress-log.png 645w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=718/media/2ngg1ufd/deploy-in-progress-log.png 718w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=860/media/2ngg1ufd/deploy-in-progress-log.png 860w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1077/media/2ngg1ufd/deploy-in-progress-log.png 1077w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1120/media/2ngg1ufd/deploy-in-progress-log.png 1120w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1436/media/2ngg1ufd/deploy-in-progress-log.png 1436w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1680/media/2ngg1ufd/deploy-in-progress-log.png 1680w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=2240/media/2ngg1ufd/deploy-in-progress-log.png 2240w" sizes="(max-width: 480px) 430px, (max-width: 768px) 718px, 1120px" width="1120" height="839" alt="Screenshot of the real-time deployment page of Netlify. The page shows a bunch of logs for the deployment process." loading="lazy" decoding="async">
</picture>
<p>When your deployment is finished, you can click on the "Preview" button on the deployment details page. This will take you to your website.<br>On the Netlify site overview page, there's also a link to your site beneath the name of your website.</p>
<p>When you navigate to the website you just deployed, you can see the Blazor WASM application is returned and everything is working:</p>
<picture>
  <img src="https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1120/media/wgtfuntn/blazor-wasm-project.png" srcset="https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=430/media/wgtfuntn/blazor-wasm-project.png 430w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=645/media/wgtfuntn/blazor-wasm-project.png 645w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=718/media/wgtfuntn/blazor-wasm-project.png 718w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=860/media/wgtfuntn/blazor-wasm-project.png 860w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1077/media/wgtfuntn/blazor-wasm-project.png 1077w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1120/media/wgtfuntn/blazor-wasm-project.png 1120w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1436/media/wgtfuntn/blazor-wasm-project.png 1436w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1680/media/wgtfuntn/blazor-wasm-project.png 1680w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=2240/media/wgtfuntn/blazor-wasm-project.png 2240w" sizes="(max-width: 480px) 430px, (max-width: 768px) 718px, 1120px" width="1120" height="206" alt="Screenshot of the Blazor WASM home page" loading="lazy" decoding="async">
</picture>
<p><strong>Almost everything that is. When you navigate to the counter page and refresh the page, you will be greeted with Netlify's 404 page:</strong></p>
<picture>
  <img src="https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=500/media/ygllpjij/counter-page-not-found.png" srcset="https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=430/media/ygllpjij/counter-page-not-found.png 430w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=500/media/ygllpjij/counter-page-not-found.png 500w" sizes="(max-width: 500px) 100vw, 500px" alt="Netlify Page Not Found 404 page" width="500" height="450" loading="lazy" decoding="async" data-udi="umb://media/a5b797c726094b708aad0a014247e745">
</picture>
<h2 id="rewrite-all-requests-to-indexhtml">Rewrite all requests to index.html&nbsp;<a href="/blog/dotnet/how-to-deploy-blazor-webassembly-to-netlify#rewrite-all-requests-to-indexhtml" aria-label="Anchor for heading: Rewrite all requests to index.html">#</a></h2>
<p>To fix the 404 issues, you need to tell Netlify to rewrite all requests to index.html. The easiest way to do this is to create a <a href="https://docs.netlify.com/configure-builds/file-based-configuration">Netlify configuration file</a> at the root of your git repository and add a rewrite rule to the file.</p>
<p><strong>Add a file at the root of your repository named "<em>netlify.toml</em>"</strong>. This configuration file uses <a href="https://toml.io/en/">the TOML configuration language</a>.</p>
<p><strong>Add the following contents to the Netlify configuration file</strong>:</p>
<pre style="color:#000000;background:#ffffff;">[[redirects]]&#10;  from = <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">/*</span><span style="color:#2a00ff; ">"</span>&#10;  to = <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">/index.html</span><span style="color:#2a00ff; ">"</span>&#10;  status = 200&#10;</pre>
<p>To learn more about the redirect configuration, visit <a href="https://docs.netlify.com/routing/redirects/#syntax-for-the-netlify-configuration-file">Netlify's Redirects and rewrites docs</a>.</p>
<p>Add, commit, and push your changes to GitHub:</p>
<pre style="color:#000000;background:#ffffff;">git <span style="color:#2a00ff; ">add</span> <span style="color:#2a00ff; ">*</span>&#10;git <span style="color:#2a00ff; ">commit</span> -m <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">Add netlify.toml and configure SPA redirect for Netlify site</span><span style="color:#2a00ff; ">"</span>&#10;git <span style="color:#2a00ff; ">push</span>&#10;</pre>
<p>Netlify will be notified of the change in the GitHub repository and automatically redeploy your site. As part of the deployment, Netlify will read the configuration file and configure your site as specified in the toml-file.</p>
<p>Once the redeploy is finished, navigate back to the counter page and hit refresh. This time you should see the counter page instead of the 404 page.</p>
<h2 id="summary">Summary&nbsp;<a href="/blog/dotnet/how-to-deploy-blazor-webassembly-to-netlify#summary" aria-label="Anchor for heading: Summary">#</a></h2>
<p>Blazor WebAssembly can be served as static files. These files can be hosted in static hosting services such as Netlify. You can create a new Netlify site using a GitHub repository as the source code. Netlify's build images contain the .NET tooling so you can build and publish your .NET applications using Netlify Build. When you refresh the Blazor WASM application while not at the root path, Netlify will return its 404 page. To return the Blazor WASM application instead, you can create a rewrite in Netlify by creating a '<em>netlify.toml</em>' file and configuring all requests to be rewritten to index.html.</p>
