在 Internet Explorer 中使用 asp.net 下载 .wav 文件
我只是尝试使用 ASP.net 处理程序将 .wav 文件发送到 Internet Explorer:
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();
}
这适用于 Firefox 和 Chrome,但我在 Internet Explorer 中只看到一个空白屏幕。为什么?
(我尝试设置“Content-Disposition”标头。如果我将其设置为“附件”,我将看到下载对话框。如果我将其设置为“内联”,我只会得到一个像以前一样空白页。
I'm just trying to sent a .wav file to Internet 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试将其嵌入到对象中
将 wav 文件发送到浏览器的页面也可以充当源,正如我在上面的示例中提到的那样,或者您可以直接指定文件名。
You can try to embed it in an 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.
事实证明,IE 试图变得聪明并忽略 HTTP 标头,如果 URL 中没有 .wav,它会假定它是文本。
通过设置别名 URL
/foo/bar.wav?audioId=123
以指向/foo/baz?audioId=123
确认了这一点。当直接访问时,IE 中不会显示任何内容,但当通过别名访问时,它会显示并播放 .wav 文件。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.