Blazor Web Assembly - On refresh getting - HTTP Error 404.0 - Not Found - after publishing the app in IIS

Dixan Thomas 60 Reputation points

I published a sample blazor WASM app and deployed it in IIS in my local machine. I'm able to access all the pages in from the hosted port, User's image

however when i refresh the page on counter or weather i'm getting below error - home page refresh is working the other two pages are having this issue. the browser is looking for a weather document as per what is shown in the network tab User's image

How can i resolve this?

A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,314 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Bruce ( 52,496 Reputation points

    When you load the app, and navigate to /weather, the blazor router is capturing the url at the client and processing. If you hit refresh, the full url is sent to the server and of course there is no /weather file to return. The server needs to be coded to load the blazor host page if it’s a valid client url. Once loaded, the client code will process the url navigation.

    You could use iis rewrite rules to implement the proper server routing.

    you can also write a hosting app, that maps the urls to the hosting page.

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    Comments have been turned off. Learn more

  3. Brando Zhang-MSFT 2,556 Reputation points Microsoft Vendor

    Hi Dixan Thomas, If you create blazor web app with the web assembly only inside the visual studio and publish to the folder. The published folder content will be like this: User's image

    Then you should set the IIS web site's folder to this folder instead of the wwwroot folder. Like below path(The web.config is outside the wwwroot not inside the wwwroot folder ): User's image

    Then we could add it inside the IIS management console: User's image

    Below is the url rewrite rule for the sample web site:

    <?xml version="1.0" encoding="UTF-8"?>
          <remove fileExtension=".blat" />
          <remove fileExtension=".dat" />
          <remove fileExtension=".dll" />
          <remove fileExtension=".webcil" />
          <remove fileExtension=".json" />
          <remove fileExtension=".wasm" />
          <remove fileExtension=".woff" />
          <remove fileExtension=".woff2" />
          <mimeMap fileExtension=".blat" mimeType="application/octet-stream" />
          <mimeMap fileExtension=".dll" mimeType="application/octet-stream" />
          <mimeMap fileExtension=".webcil" mimeType="application/octet-stream" />
          <mimeMap fileExtension=".dat" mimeType="application/octet-stream" />
          <mimeMap fileExtension=".json" mimeType="application/json" />
          <mimeMap fileExtension=".wasm" mimeType="application/wasm" />
          <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
          <mimeMap fileExtension=".woff2" mimeType="application/font-woff" />
            <add mimeType="application/octet-stream" enabled="true" />
            <add mimeType="application/wasm" enabled="true" />
            <rule name="Serve subdir">
              <match url=".*" />
              <action type="Rewrite" url="wwwroot\{R:0}" />
            <rule name="SPA fallback routing" stopProcessing="true">
              <match url=".*" />
              <conditions logicalGrouping="MatchAll">
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
              <action type="Rewrite" url="wwwroot\" />

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments