1

I've created a HttpHandler (.ashx) for clients download content (videos) from my website. First I was using the WriteFile method, that I realized it was requiring to much memory and then I decided to change it to TransmitFile method.

But one weird thing happened, I wasn't able to make more than one download anymore. I had to wait a download finishes and start the other.

Basically the code is like this:

        System.IO.FileInfo file = new System.IO.FileInfo(file_path);

        context.Response.Clear();

        if (flagH264)
        {
            context.Response.ContentType = "video/mp4";
        }
        else
        {
            context.Response.ContentType = "video/x-ms-wmv";
        }

        context.Response.AddHeader("Content-Length", file.Length.ToString());
        context.Response.AddHeader("Content-Disposition", "attachment; filename=" + name);

        //context.Response.WriteFile(file_path.Trim());
        context.Response.TransmitFile(file_path.Trim());
        context.Response.Flush();

Anyone may know what is this problem?

tshepang
  • 12,111
  • 21
  • 91
  • 136

1 Answers1

0

I found what was the problem.

The HttpHandler (ashx) I was using for the download page was implementing an interface IRequireSessionState that gave me read/write rights to manipulate session data. When using TransmitFile method IIS blocks any operation on the system to protect session data from being altered.

The solution was changing the IRequireSessionState for IReadOnlySessionState, that gives only reading access to session data and there was no need to provide any kind of security, blocking user actions.