Download .wav file with asp.net in Internet Explorer
I'm just trying to sent a .wav file to Intern开发者_如何学Cet Explorer with an ASP.net Handler:
public void ProcessRequest(HttpContext context)
{
HttpResponse response = context.Response;
response.ContentType = "audio/x-wav";
response.WriteFile("MyWav.wav");
response.AddHeader("Content-Length", "304578");
response.Flush();
}
This works for Firefox and Chrome but I'm just presented with a blank screen in Internet Explorer. Why?
(I've tried setting the "Content-Disposition" header. If I set it to "attachment" I am presented with the download dialog. If I set it to "inline", I just get a blank page like before.
You can try to embed it in an object
<object
classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95">
<param name="AutoStart" value="1" />
<param name="FileName" value="GiveYourPageNameHere.aspx" />
</object>
The page that sends the wav file to the browser can also act as the source as i've mentioned in the example above or you can directly specify the filename.
It turns out that IE tries to be clever and ignores the HTTP headers and if there isn't .wav in the URL it assumes it's text.
This was confirmed by setting up an alias URL /foo/bar.wav?audioId=123
to point to /foo/baz?audioId=123
. When accessed directly nothing is displayed in IE, but when accessed via the alias it displays and plays the .wav file.
精彩评论