Odd behavior with BinaryWrite and Windows Media Player

S

sstreaker

I'm serving an MP3 file via a BinaryWrite from an ASPX file. If I have
Content-Disposition set to "inline", WMP opens as expected but hits my
ASPX page 3 times and then finally play the file. This is not
desirable because the impact on the server is idential to that if 3
different clients hit the same page.

If I have Content-Disposition set to "attachment", IE prompts with
Save/Open as expected, and if I choose save, the ASPX page is hit only
once and the MP3 is successfully saved and playable, as expected.

Analysis of the data being streamed to the browser indicates that the
MP3 file is encoded properly, complete, and playable by WMP.

Based on these observations, I can only assume at this point that my
server-side code is correct as far as how I am writing the file to the
response stream.

So, why is WMP hitting my page more than once? What is it looking for?

Code is pretty straight-foward and follows. Thanks in advance! =)

-----------------

Response.ContentType = "audio/mpeg";
Response.Buffer = true;
Response.BufferOutput = true;

char[] chars = new char[4096];
int i;

// FYI mystringreader is a placeholder for Process.StandardOutput,
// which is the source of the data

while((i=mystringreader.Read(chars,0,chars.Length))>0) {
Response.BinaryWrite(Encoding.Default.GetBytes(chars));
Response.Flush();
}
 
B

Bruce Barker

this is standard behavior for IE active/x plugins. it used to be 5
downloads, so 3 an improvement. here is what happens:

1) ie hits the site and gets a content type that only supported by a
plugin. - cancels the download
2) ie does a second hit to check the content type (may be a head request)
3) ie loads the plugin, and gives it the url
4) the plugin downloads the url.

if you tell IE to cache the file, the additional requests can come from the
cache.

-- bruce (sqlwork.com)
 
S

sstreaker

OK, I'm seeing this behavior and it makes sense. So, how do I tell IE
to cache the file like you mentioned? And with this technique you are
saying my pages will only be hit once?
 
B

Bruce Barker

you output the headers to allow caching, and return a consistant last
modified date (see HttpCachePolicy). also you should check for a head
request, and only return the headers, no content

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top