English 中文(简体)
How to create Large resumable download from a secured location .NET
原标题:

I need to preface I m not a .NET coder at all, but to get partial functionality, I modified a technet chunkedfilefetch.aspx script that uses chunked Data Reading and writing Streamed method of doing file transfer, to get me half-way.

iStream = New System.IO.FileStream(path, System.IO.FileMode.Open, _
    IO.FileAccess.Read, IO.FileShare.Read)
dataToRead = iStream.Length

Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Length", file.Length.ToString())
Response.AddHeader("Content-Disposition", "attachment; filename=" & filedownload)

  Read and send the file 16,000 bytes at a time.  
While dataToRead > 0
    If Response.IsClientConnected Then
        length = iStream.Read(buffer, 0, 16000)
        Response.OutputStream.Write(buffer, 0, length)
        Response.Flush()
        ReDim buffer(16000)   Clear the buffer  
        dataToRead = dataToRead - length
    Else
          Prevent infinite loop if user disconnects  
        dataToRead = -1
    End If
End While

This works great on files up to 2GB and is fully functioning now.. But only one problem it doesn t allow for resume.

I took the original code called it fetch.aspx and pass an orderNUM through the URL. fetch.aspx&ordernum=xxxxxxx It then reads the filename/location from the database occording to the ordernumber, and chunks it out from a secured location NOT under the webroot.

I need a way to make this resumable, by the nature of the internet and large files people always get disconnected and would like to resume where they left off. But any resumable articles i ve read, assume the file is within the webroot.. ie. http://www.devx.com/dotnet/Article/22533/1954 Great article and works well, but I need to stream from a secured location.

I m not a .NET coder at all, at best i can do a bit of coldfusion, if anyone could help me modify a handler to do this, i would really appreciate it.

Requirements:

  • I Have a working fetch.aspx script that functions well and uses the above code snippet as a base for the streamed downloading.
  • Download files are large 600MB and are stored in a secured location outside of the webroot.
  • Users click on the fetch.aspx to start the download, and would therefore be clicking it again if it was to fail. If the ext is a .ASPX and the file being sent is a AVI, clicking on it would completely bypass an IHTTP handler mapped to .AVI ext, so this confuses me
  • From what I understand the browser will read and match etag value and file modified date to determine they are talking about the same file, then a subsequent accept-range is exchanged between the browser and IIS. Since this dialog happens with IIS, we need to use a handler to intercept and respond accordingly, but clicking on the link would send it to an ASPX file which the handeler needs to be on an AVI fiel.. Also confusing me.
  • If there is a way to request the initial HTTP request header containing etag, accept-range into the normal .ASPX file, i could read those values and if the accept-range and etag exist, start chunking at that byte value somehow? but I couldn t find a way to transfer the http request headers since they seem to get lost at the IIS level.

  • OrderNum which is passed in the URL string is unique and could be used as the ETag

        Response.AddHeader("ETag", request("ordernum"))
    
  • Files need to be resumable and chunked out due to size.

  • File extensions are .AVI so a handler could be written around it.
  • IIS 6.0 Web Server

Any help would really be appreciated, i ve been reading and reading and downloading code, but none of the examples given meet my situation with the original file being streamed from outside of the webroot. Please help me get a handle on these httphandlers :)

问题回答

暂无回答




相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签