4

I have a Blazor WASM hosted on Azure Static App, website works fine. But I realized if you give someone a link to one of the pages on the site like https://www.myblazor.com/path/do, and this person never visited this site before, the site will display:

The requested content does not exist.

HttpStatusCode: 404
ErrorCode: WebContentNotFound
RequestId : 18382fd7-f01e-0015-31cc-67b610000000
TimeStamp : 2021-06-23T01:10:44.3896906Z

The person must visit the root first https://www.myblazor.com, after the site loads, he can then manually go to the special page.

Why is this? Is it because I am using the static file service, instead of regular App Service? Is it possible to make it work? It's very common to link to a specific page on the website, not necessarily the root.

Thanks for any advice.

3 Answers 3

11

You need to configure a fallback route. Add a file named staticwebapp.config.json in the same folder as your Blazor app's csproj file with this content:

{
    "navigationFallback": {
        "rewrite": "/index.html"
    }
}

See this example app here: https://github.com/staticwebdev/blazor-starter/blob/main/Client/staticwebapp.config.json

Sign up to request clarification or add additional context in comments.

1 Comment

In my project (.NET 7 Blazor WebAssembly) the staticwebapp.config.json should be placed into the wwwroot folder.
1

Looking at your error message, you might actually be using Azure Storage static website hosting, which is a different service than Azure Static Web Apps.

To set up a fallback route in Azure Storage static websites, see the "enable deep linking" section of this blog post.

Azure Static Web Apps provides better control for this. See my other answer if you want to try that. (disclaimer: I work on this service)

Comments

0

I've found the answer from this blog:

Blazor WASM 404 error and fix for GitHub Pages

Although it's intended for Github pages hosting, it's the same concept as Azure Static App hosting. Works like a charm :-)

Make sure you login to your Azure portal and set the page not found setting to 404.html and save this file to your root directory, together with index.html.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.