HttpHandler Returns a zero byte of length []

I have a custom HttpHandler that calls a web service to get a file. In the test, I am calling the production web service and the HttpHandler is returning the file correctly. When I test it in a production environment on a server, it also works. However, if I call the HttpHandler from a remote client (not the server), the file name and size are set correctly, but the file bytes downloaded are zero. Any ideas?

+1


a source to share


1 answer


So here's the deal. I created a multi-pass range handler (you need to implement an RFC to stream content, say iPhone or Adobe Reader). The spec is supposed to allow the file to be processed when the client requests a range of bytes instead of the entire array. The problem with my handler came when the client wanted the whole BLOB:

if (context.Request.Headers[HEADER_RANGE] != null)
{
  ...
}
else
{
    context.Response.ContentType = contentItem.MimeType;
    addHeader(context.Response, HEADER_CONTENT_DISPOSITION, "attachment; filename=\"" + contentItem.Filename + "\"");
    addHeader(context.Response, HEADER_CONTENT_LENGTH, contentItem.FileBytes.Length.ToString());
    context.Response.OutputStream.Write(contentItem.FileBytes, 0, contentItem.FileBytes.Length);
}

      

Notice something that is missing ???



I forgot to include:

context.Response.Flush();

      

After adding this line of code, it started working in a production environment. However, it is very strange to me that this works on the server and not on any clients. Anyone who can shed some light on why this would be?

+1


a source







All Articles