MapStaticAssets is breaking a background video from playing

Daniel Cooper 30 Reputation points
2025-11-24T16:07:35.53+00:00

I have a rather large Blazor WASM application running on Dot Net 9. The login page has a background video. Everything works well. We are making some significant changes and want to include an upgrade to Dot Net 10.

The upgrade results in a Blazor.web.js 404 error at runtime which (from research) is fixed by adding MapStaticAssets to the program.cs. Even though UseStaticFiles is still there, the video (mp4) doesn't play - or is included in wwwroot. jpg and svg files appear. it's just the video. It doesn't matter where I place the MapStaticAssets.

I cannot find any official guidance on how to address this issue. There are plenty of ideas on the various forums but most don't work for me.

So, is there a way of avoiding the Blazor.web.js 404 error or what is the correct configuration for MapStaticAssets to play the video?

I've lost 2 days on this already and any help would be very much appreciated.

Developer technologies | .NET | Blazor
{count} votes

Answer accepted by question author
  1. Raymond Huynh (WICLOUD CORPORATION) 3,645 Reputation points Microsoft External Staff Moderator
    2025-11-25T07:58:48.8633333+00:00

    Hi Daniel Cooper,

    Thanks for clarifying the sequence.

    The fact the video works in production (Azure) but fails locally suggests that there's a difference in how static files, especially videos which use byte-range requests, are processed by MapStaticAssets() versus your local hosting pipeline (Kestrel). There's a known issue reported in the ASP.NET Core repo titled "MapStaticAssets returns incorrect Content-Length for custom Range". The issue link is:

    https://github.com/dotnet/aspnetcore/issues/63320
    (Disclaimer: Some links are non-Microsoft website. The pages appear to be providing accurate, safe information. Watch out for ads on the site that may advertise products frequently classifies as a PUP (Potentially Unwanted Products). Thoroughly research any product advertised on the site before you decide to download and install it. )

    In that issue, a video file served via MapStaticAssets() caused a mismatch between Content-Range and Content-Length, which breaks playback in some browsers.

    Here's a more targeted workaround you can test locally:

    1. In your server project's .csproj, exclude the .mp4 video file(s) from static-web-asset processing:
    <ItemGroup>
    <Content Update="wwwroot/videos/**/*.mp4"
                  CopyToOutputDirectory="PreserveNewest">
    <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
    </Content>
    </ItemGroup>
    <ItemGroup>
    <StaticWebAsset Remove="wwwroot/videos/**/*.mp4" />
    </ItemGroup>
    
    1. Run locally and check whether the video plays. If yes, then you've effectively sidestepped the issue locally by letting UseStaticFiles() serve the video.
    2. For confirmation, open your browser's Developer Tools → Network tab, request the video and inspect the headers:
      • Check if the request has a Range header
      • Check if the response has Accept-Ranges: bytes
      • Check if Content-Range is present and if Content-Length matches the range length (rather than full file size). If Content-Length equals full file size despite a partial request.

    Hope this helps!


2 additional answers

Sort by: Most helpful
  1. Q&A Assist
    2025-11-24T16:07:50.8866667+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To address the issue with the background video not playing after implementing MapStaticAssets, ensure that the video file is correctly placed in the wwwroot directory and that the file path used in your application is accurate. Here are some steps you can follow:

    1. Verify Video Path: Ensure that the path to the video file in your code is correct. It should point to the location within the wwwroot directory.
    2. Check MIME Types: Ensure that the server is configured to serve the video file type (e.g., .mp4). You can check the server's configuration to ensure that the MIME type for .mp4 is set correctly.
    3. Order of Middleware: The order in which you call UseStaticFiles and MapStaticAssets in your Program.cs file matters. Typically, you should call UseStaticFiles() before MapStaticAssets(). Here’s an example:
         app.UseStaticFiles();
         app.MapStaticAssets();
      
    4. Caching Issues: Sometimes, caching can cause issues with loading updated files. Clear your browser cache or test in an incognito window to see if that resolves the issue.
    5. Check for Errors: Use the browser's developer tools to check for any errors in the console or network tab that might give you more insight into why the video is not loading.

    If you continue to experience issues, consider reviewing the official documentation for any updates or changes related to static file handling in Blazor applications.


    References:

    0 comments No comments

  2. Bruce (SqlWork.com) 81,971 Reputation points Volunteer Moderator
    2025-11-24T21:32:01.0466667+00:00

    With blazor WASM, static files are just server files cached by manifest preload. When using the separate server, client projects, the static are hosted by the server. When it creates the manifest it should include them, but from the client they are just root urls.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.