Search code examples
c#.netasp.net-mvcteleriktelerik-radcaptcha

How to play Telerik RadCaptcha .wav file without open/save dialog


I've got a link on my page allowing the user to listen to a captcha code, clicking the link will show a open/save dialog. If possible, I'd like the browser to just play the file, instead of requiring user interaction.

This is how I return the audio to the browser:

byte[] filebytes = Helper.TextToAudioBytes(code);
Response.AddHeader("Content-Disposition", "attachment; filename=sound.wav");
return File(filebytes, "audio/wav");

Solution

  • You are sending the Content-Disposition header with value attachment. This tells the browser that the file should be saved and not handled as normal content. Removing this will allow the browser to handle the file in a manner based on the browser settings.

    Note that the browser settings might still be "save the file" or whatever the user has decided, not necessarily "play the sound".