Razor Page unable to load resource error

kobosh 176 Reputation points

Hi I am following this tutorial

It uses razor app to play mp3 files. I added test.wav file to sounds folder. When I run app I get :
Failed to load resource: the server responded with a status of 404 ()
I tried to use full path D;//......//sounds/test.wav and I get acces to local not allowed. I started visual studio as admin.

A set of technologies in the .NET Framework for building web applications and XML web services.
4,376 questions
0 comments No comments
{count} votes

Accepted answer
  1. Brando Zhang-MSFT 3,446 Reputation points Microsoft Vendor

    Hi @kobosh ,

    According to your description and error message, this issue is related with you are using the static path instead of using relative path. This is the reason why you get this error.

    I suggest you could try to modify the path like below:

    For example:

    If your mp3 file is inside the wwwroot/sounds folder, then you could directly use below codes to get the mp3 file.

    ~ means the application's root folder, in blazor server app it means wwwroot folder.

    <audio id="player2">  
        <source id="playerSource2" src="~/Sounds/aaa.mp3" />  

2 additional answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 61,181 Reputation points

    The browser can not access the folder. The website must expose the mp3 as a url. You will need to implement range requests.

    You may want to put the sound files in a separate folder and have iis server directly. The use the iis url on the media tag

  2. AgaveJoe 27,581 Reputation points

    Your post is very confusing and clarification will help us help you. First, this is a Blazor application not Razor Pages.

    The Audio file must be located on the server, not the client machine. Does the server have access to the audio file or is the audio file on the client's machine?

    A 404 is a standard HTTP not found error. It means the URL did not match an action. What is the URL that returns the 404?

    Can you share the PlayAudioFile function?